I've a general problem with my application. I want to use lazy initialization with an Array class I've made, to improve performances; all works fine when all code is in a single *.h file, but compiler returns a linker error when I split the code in *.h*.cpp files. In the header file I have a
template <class T>
class simpleArray { ... some methods\operators declarations. ... }
and
template <typename T, typename derType=simpleArray<T>>
class myArray{.... some methods\operators declarations. ... }
and I've the explicit declaration of:
template class myArray<double>;
template class myArray<int>;
template class simpleArray<double>;
template class simpleArray<int>;
In the *.cpp file I've the implementation of methods and operators. Particularly I have two assignments operators:
template <class T, class derType>
myArray<T,derType>& myArray<T,derType>::operator= (myArray<T,derType> const& right)
{... some code ...}
template<class T, class derType>
template <class T2, class R2>
myArray<T,derType>& myArray<T,derType>::operator= (myArray<T2,R2> const& right)
{ ... some code ...}
The first one works fine, the second one (Arra=Array) returns the following errors:
Error 70 error LNK1120: 1 unresolved externals
Error 69 error LNK2019: unresolved external symbol "public: class myArray <double,class simpleArray<double> > & __thiscall myArray <double,class simpleArray<double> >::operator=<int,class simpleArray<int> >(class myArray <int,class simpleArray<int> > const &)"
May you please suggest some solutions? Do I have to include all code in the same file? I hope have been clear. Thank you for the support!
Ps. are there some "best practice" documents about code organization when using template?