J
JC
I'm having a problem getting an explicit specialization to work
properly. I have a class like this, declared in a header:
class SomeClass {
template <typename T> class Nested {
void function ();
};
};
I also have the generic implementation Nested::function() in that same
header:
template <typename T> void SomeClass::Nested<T>::function () {
// ...
}
However, I want to specialize function() for a certain type, e.g. a
double. So the explicit specialization is:
template <> void SomeClass::Nested<double>::function () {
}
The problem is, if I put that in the header, the linker complains
about the function being defined in multiple object files. However, if
I put it in a source file, then the other source files that include
that header don't see the explicit specialization.
How can I make this work so that the linker is happy, and the explicit
specialization is used everywhere?
Thanks,
Jason
properly. I have a class like this, declared in a header:
class SomeClass {
template <typename T> class Nested {
void function ();
};
};
I also have the generic implementation Nested::function() in that same
header:
template <typename T> void SomeClass::Nested<T>::function () {
// ...
}
However, I want to specialize function() for a certain type, e.g. a
double. So the explicit specialization is:
template <> void SomeClass::Nested<double>::function () {
}
The problem is, if I put that in the header, the linker complains
about the function being defined in multiple object files. However, if
I put it in a source file, then the other source files that include
that header don't see the explicit specialization.
How can I make this work so that the linker is happy, and the explicit
specialization is used everywhere?
Thanks,
Jason