the comments. Do I need to duplicate both the interface and the
implementation parts? and what is the syntax for the specialized method
implementations?
I took the code from the message to which you replied, and it did
compile OK for me.
Can you please post both the shortest version of the code that gives the
error *and* the error (please also mark the line to which it refers
using some kind of comment, don't post all line numbers with the code),
like this:
// boo.cpp
...
class Boo {
Boo(B00&); // line 536
};
error (boo.cpp: 536) : 'B00' undefined
V
I am simply asking what the syntax is when implementing the methods belonging to the specialized template, outside of the specialized template. I already posted the code, the erroneous part was commented out with /* and */ with // what is the syntax here?
Here it is again without the erroneous part commented out:
//------------------------------------------------
class A
{
};
//------------------------------------------------
//------------------------------------------------
class B
{
};
//------------------------------------------------
//------------------------------------------------
template<class T>
class MyTemplateClass
{
public:
MyTemplateClass();
~MyTemplateClass();
void Foo(const T & arg);
};
//------------------------------------------------
template<class T>
MyTemplateClass<T>::MyTemplateClass()
{
}
//------------------------------------------------
template<class T>
MyTemplateClass<T>::~MyTemplateClass()
{
}
//------------------------------------------------
template<class T>
void MyTemplateClass<T>::Foo(const T & arg)
{
}
//------------------------------------------------
//------------------------------------------------
// Specialization
// So I have to redo the entire interface a second time even though I am
// only adding one new method?
template<>
class MyTemplateClass<class B>
{
public:
MyTemplateClass();
~MyTemplateClass();
void Foo(const B & arg);
void Bar(const B & arg);
};
//------------------------------------------------
//------------------------------------------------
// I also must do the implementation of every method even though they
// are all the same, except for adding one new one?
// and what is the syntax?
template<>
MyTemplateClass<class B>::MyTemplateClass()
{
}
//------------------------------------------------
template<class T>
MyTemplateClass<double>::~MyTemplateClass()
{
}
//------------------------------------------------
template<class T>
void MyTemplateClass<T>::Foo(const T & arg)
{
}
//------------------------------------------------
template<>
void MyTemplateClass<B>::Bar(const B & arg)
{
}
//------------------------------------------------
int main()
{
A argTypeA;
B argTypeB;
MyTemplateClass<A> templateTypeA;
MyTemplateClass<B> templateTypeB;
templateTypeA.Foo(argTypeA);
templateTypeB.Foo(argTypeB);
return 0;
}