I am trying to define a constructor for an explicitly specialized class template outside the class definition, as so:
template <typename T>
struct x;
template <>
struct x<int> {
inline x();
/* This would have compiled:
x() {
}
*/
};
template <> // Error
x<int>::x() {
}
But it seems to be an error. Comeau says: error: "x<int>::x()" is not an entity that can be explicitly specialized
, even though the complete class is what being specialized.
What's the issue here?
Don't specify template<>
for the definition:
template <typename T>
struct x;
template <>
struct x<int> {
x();
};
inline x<int>::x(){}
Edit: The constructor definition isn't a specialization, so template<>
is unnecessary. It's the definition of the constructor of a specialization. So, you just need to specify the type like for any other non-template class.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With