// forward declarations
template<typename charType> class string;
template<typename charType> string<charType> operator + (const string<charType>&, const string<charType>&);
template<typename charType> string<charType> operator + (const string<charType>&, const char*);
class string {
...
friend string<charType> operator + <>(const string<charType>& str1, const string<charType>& str2);
friend string<charType> operator + <>(const string<charType>& str1, const char* str2);
}
Above you can see my current header file for my string class (I found this from another Answer on SO). How do you provide a correct definition for these declaritions?
// Operators
template <typename charType>
string<charType> operator+ (const string<charType>& str1, const string<charType>& str2)
{
charType* tmp = new charType[str1._length + str2._length + 1];
memcpy(tmp, str1._data, str1._length);
memcpy(tmp + str1._length, str2._data, str2._length + 1);
return string<charType>(tmp, str1._length + str2._length);
}
This leads to an unresolved external. (Presumably because the function header's dont match even when adding a <>)
I'm working on the newest Version of VS2017 (thus using microsoft's compiler). Taken from a comment: 'how to instantiate a particular template instance in a translation unit, so that the template instance can be resolved from other translation units where the template definition is not available.'