J
jason.cipriani
I have a template class declared in a header, with explicit
specialization of certain member functions defined in a source file.
However, I want to define the specialized member functions in the
header, not a separate source file. They can't be defined outside the
class declaration in the header, as that leads to multiple definitions
of the functions in all the source files that include the header.
However, I don't know the syntax for defining them inside the class
declaration -- and that's my question: is this possible and, if so,
what's the syntax? Right now I have some a test program like this:
=== BEGIN EXAMPLE ===
#include <iostream>
using std::cout;
using std::endl;
template <int N> struct A {
A ();
// <----- I want to put the specialized implementations here.
};
template<> A<1>::A () { cout << "1!" << endl; }
template<> A<2>::A () { cout << "2!" << endl; }
int main () {
A<1> x;
A<2> y;
return 0;
}
=== END EXAMPLE ===
And what I really want to do is define both of those specialized
constructors in the class declaration instead.
Thanks,
Jason
specialization of certain member functions defined in a source file.
However, I want to define the specialized member functions in the
header, not a separate source file. They can't be defined outside the
class declaration in the header, as that leads to multiple definitions
of the functions in all the source files that include the header.
However, I don't know the syntax for defining them inside the class
declaration -- and that's my question: is this possible and, if so,
what's the syntax? Right now I have some a test program like this:
=== BEGIN EXAMPLE ===
#include <iostream>
using std::cout;
using std::endl;
template <int N> struct A {
A ();
// <----- I want to put the specialized implementations here.
};
template<> A<1>::A () { cout << "1!" << endl; }
template<> A<2>::A () { cout << "2!" << endl; }
int main () {
A<1> x;
A<2> y;
return 0;
}
=== END EXAMPLE ===
And what I really want to do is define both of those specialized
constructors in the class declaration instead.
Thanks,
Jason