I have a template class
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;
...
};
and derived class:
class WavesetTime : public WavesetTemplate<double>
{
public:
WavesetTime(){} ;
virtual ~WavesetTime() {} ;
WavesetTime& operator=(const WavesetTime& rhs) { WavesetTemplate<double>:perator=(rhs);return *this;} // call base operator= function
... //other type specific functions
};
This works...
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
BUT THIS
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
gives the 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.
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;
...
};
and derived class:
class WavesetTime : public WavesetTemplate<double>
{
public:
WavesetTime(){} ;
virtual ~WavesetTime() {} ;
WavesetTime& operator=(const WavesetTime& rhs) { WavesetTemplate<double>:perator=(rhs);return *this;} // call base operator= function
... //other type specific functions
};
This works...
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
BUT THIS
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
gives the 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.