yet another arcane c++ question!
May. 14th, 2009 11:56 amIs this well-formed (assume nothing else in the translation unit)?
template <class T> class R {
int f();
};
template class R<int>;
Now, how about this?
template <class T> class S {
int f();
};
template <> int S<float>::f() { return 10; }
template class S<int>;
The crux here being that, in both cases, a definition of S is in scope at the point of the explicit instantiation, but a definition of S::f isn’t (only a specialization, in the second case). Section 14.7 of the C++ standard is so confusing that the authors included a joke about it in the text. GCC doesn’t complain at all, but I don't trust it to get templates exactly pedantically correct.