I have the following code which compiles in VC6 :
Text.h:
template
class CTextT
{
public:
friend CTextT add(const CTextT&
Of course it does give a linker error. The add()
function you made a friend
isn't a function template! It is a non-template function declared inside a class template. As a result, you won't be able to define this function as a template, either. You can directly define it at the friend
declaration.
The alternative is to declare the function template prior to the class template. Of course, this requires a declaration of the class template, too. The following should work:
template class CTextT;
template CTextT add(CTextT const&, CTextT const&);
template
class CTextT
{
friend CTextT add<>(CTextT const&, CTextT const&);
// ...
};
Now the template definition you have give should work.