I have a template class
and derived class:Code:template<class T> class WavesetTemplate { public: ... WavesetTemplate<T>& operator=( const WavesetTemplate<T>& ); friend WavesetTemplate<T> operator*(const WavesetTemplate<T>& lhs, const WavesetTemplate<T>& rhs); protected: vector<vector<T> > m_TemplateData; ... };
This works...Code:class WavesetTime : public WavesetTemplate<double> { public: WavesetTime(){} ; virtual ~WavesetTime() {} ; WavesetTime& operator=(const WavesetTime& rhs) { WavesetTemplate<double>::operator=(rhs);return *this;} // call base operator= function ... //other type specific functions };
BUT THISCode:WavesetTemplate<double> x,y,z; x.SetWave(0.0,flat10,0.1); //set some data y.SetWave(0.0,ramp,0.1); //set some data z=x * y; // this works
gives the compile error:Code:WavesetTime x,y,z; x.SetWave(0.0,flat10,0.1); //set some data y.SetWave(0.0,ramp,0.1); //set some data z=x * y; // compile error
binary '=' : no operator defined which takes a right-hand operand of type 'class WavesetTemplate<double>' (or there is no acceptable conversion).
I also get the same problem when operator* is a member function, rather than here where it is non-member function.
The only way I can get this compile error to disappear is to put operator* into the derived class WavesetTime, which rather defeats the point of templates.
I would be very grateful if anyone could suggest a solution to this problem. Thank you.




Reply With Quote