Surcharge opérateur ac tableau
imogen
-
titine -
titine -
J'explique:
J'ai une classe POLYNOME qui a comme seul attribut un tableau de coefficient TABCOEFF
Je dois surcharger l'opérateur + ( avec 2 objets de ma classe
Là je voudrais utiliser mon tableau
Le problème est:
si j'utilise mon TABCOEFF erreur car c'est un élèment en private
si j'utilise un GETTABCOEFF(int indice) j'ai une autre erreur :
non-lvalue in assignment
si vous avez une idée ca m'aiderai bcp
merci
J'ai une classe POLYNOME qui a comme seul attribut un tableau de coefficient TABCOEFF
Je dois surcharger l'opérateur + ( avec 2 objets de ma classe
TPOLYNOME operator + (TPOLYNOME &P,TPOLYNOME Q)
Là je voudrais utiliser mon tableau
Le problème est:
si j'utilise mon TABCOEFF erreur car c'est un élèment en private
P.TABCOEFF[i]
si j'utilise un GETTABCOEFF(int indice) j'ai une autre erreur :
non-lvalue in assignment
P.GETTABCOEFF(i)
si vous avez une idée ca m'aiderai bcp
merci
2 réponses
-
Comment tu veux qu'on t'aide... il n'y a pas une ligne de ton code... mais en general c'est des erreurs du style 'P.' au lieu de 'P->' comme par exemple c'est sans doute le cas dans ton appel a GETTABCOEFF
-
dans le point h:
class TPOLYNOME { private: double TABCOEFF[]; public: TPOLYNOME(); TPOLYNOME(const TPOLYNOME &_POLYNOME); ~TPOLYNOME(); double GETTABCOEFF(int indice)const; TPOLYNOME operator [](int index); friend ostream& operator << (ostream &o, TPOLYNOME &_POLYNOME); friend TPOLYNOME operator + (const TPOLYNOME &P,TPOLYNOME &Q); };
dans le .cpp
double TPOLYNOME::GETTABCOEFF(int _indice)const { return TABCOEFF[_indice]; } /*TPOLYNOME operator[](int index) { return TABCOEFF[index]; }//fin operator [] */ ostream& operator << (ostream &o, TPOLYNOME &_POLYNOME) { for (int i=MAX;i>0;i--) { o<<_POLYNOME.TABCOEFF[i]<<" x^"<<i; } //return 0; } TPOLYNOME operator + (TPOLYNOME &P,TPOLYNOME Q) { for (int i=0;i<MAX;i++) { P.GETTABCOEFF(i) += Q.GETTABCOEFF(i); } }
dc voilà le code
avec mes opérateurs [] et + qui ne fonctionne pas