I have the following code which compiles in VC6 :
Text.h:
template
class CTextT
{
public:
friend CTextT add(const CTextT&
The solution is following:
template
class CTextT
{
public:
template
friend CTextT add(CTextT const&, CTextT const&) ;
friend CTextT operator+(const CTextT& string1, const CTextT& string2)
{ return ::add(string1, string2); }
};
template
CTextT add(CTextT const&, CTextT const&)
{
CTextT temp ;
return temp ;
}
I found the following link to MSDN explaining how to add friend functions in templates - http://msdn.microsoft.com/en-us/library/f1b2td24.aspx.
I tested and it works for VS2010 and VS2012. VC6 does not need the second template declaration (it takes it from the class) and in VC6 this code will not compile anymore - will return INTERNAL COMPILER ERROR.