I have two classes, and I want to surdefine the operator = .
class Composant {
string description;
...
virtual const Composant& operator=(const Composant &c)
{
description = c.description;
return *this;
}
}
And the other one inherited :
class Ecran : Composant {
int format, pitch;
double taille;
...
const Ecran& operator=(const Ecran &e)
{
format = e.format;
taille = e.taille;
pitch = e.pitch;
//traiter composant
Composant::operator=(e);
}
Example of the code in the main :
Composant *p=new Ecran(.....);
Composant *t=new Ecran(.....);
(*p)=*t;
Is this the correct way to do it ?
I assume that we MUST put the surdefinition of the operator = in virtual, everytime we have this type of inheritance then ? same for the operator == and so on ...