Ioannis Vranos wrote:
... You can think of every function _definition_ as consisting of
a declaration and a body. So, if you already have a definition, just
replace the body with a semicolon :-)
Yes that's what I thought. However it is the first time I see a
constructor definition (and declaration!) that is valid outside of the
class body and invalid in the inside.
...
It makes sense to me. This member specialization is only relevant to one
concrete specialization of the class template (the one with 'T ==
double'), not to the entire class template. It would be strange to see
it inside.
Now, if the constructor itself was a template
template<class T> class CL
{
public:
template<class U> CL(const U& t) {}
...
};
then it would be logical to allow declaring/defining it's
specializations inside the class definition
template<class T> class CL
{
public:
template<class U> CL(const U& t) {}
template<> CL(const double& t) { /* ... */ }
template<> CL(const int& t) { /* ... */ }
...
};
The above is only provided as a syntactical sketch. The latter code is
still illegal in C++ for a completely unrelated reason: member templates
cannot be explicitly specialized without explicit specialization of the
enclosing class template (come to think of it, I still don't know the
rationale for this limitation).
--
Best regards,
Andrey Tarasevich