Surcharge opérateur ac tableau

Fermé
imogen - 24 avril 2005 à 22:27
 titine - 28 avril 2005 à 23:38
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

 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

Kermitt31 Messages postés 3669 Date d'inscription jeudi 15 juillet 2004 Statut Contributeur Dernière intervention 8 août 2006 492
25 avril 2005 à 08:40
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
0
je pense pas que ce soit une histoire de pointeur ds ce code
0
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
0