I've encountered a problem concerning templates, perhaps someone knows how to fix this..
I have a template class "template<class T> class myclass"
this class has a memberfunction that is supposed to take as a parameter an instance of the class:
template<class T> ret myclass<T>::myfunc( myclass<T> )
so far so good.. but now for the part I don't get.. The functions parameter is to be the class with an arbitrary type .. not necessarily the type of the 'this' class...
something like this.. just to make you see what I wan't..
template<class T, class T1> ret myclass<T>::myfunc( myclass<T1> )
The above statement doesn't do the trick so how should I write..
If you want the class to have two template types you have to put both of them every time you refer to to the class name. So adding a second template type won't work, because each instantiation would still have its arguments be of its own type anyway.
I think the easiest thing to do would just to put up with multiple overloads and try this:
template<class T> ret myclass<T>::myfunc( myclass<int> )
template<class T> ret myclass<T>::myfunc( myclass<float> )
template<class T> ret myclass<T>::myfunc( myclass<double> )
... and so on.
Also, most compilers let you template individual member functions. (The one I was using this summer didn't, though.) So there might be a slightly more advanced way as well.