problème au surcharge d'opérateur =
Bonjour,
j'ai une structure comme suit
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
|
class P
public:
char* DataFile;
int nbter;
int nbser;
int nbf;
int nbgp;
vector<S *> ser;
vector<F *> f;
vector<T *> ter;
vector<G *> grp;
Cellule* cell;
public:
P(char* df);
P(const Pe& p);
Properator=(const P &p);
virtual ~P();
}; |
Et j'ai défini l'opérateur= comme ça
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
|
P P::operator=(const P &p)
{
nbter=p.nbter;
nbsers=p.nbser;
nbf=p.nbf;
nbgp=p.nbgp;
cell=p.cell;
ser.reserve(p.ser.size()); // optimize insertion
ter.reserve(p.ter.size());
grp.reserve(p.grp.size());
f.reserve(p.f.size());
for (vector<S *>::const_iterator its = p.ser.begin();its != p.ser.end();its++)
ser.push_back(new S(**its));
for (vector<F *>::const_iterator itf = p.f.begin();itf != p.f.end();itf++)
f.push_back(new F(**itf));
.
.
.
return *this;
} |
Mais quand je declare 2 objet de type P: P a,b;
je modifie a, après a=b; l'affectation ca se produit pas a reste différente de b
Merci d'avance