Surcharge opérateur ac tableau

imogen -  
 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

 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

  1. Kermitt31 Messages postés 3679 Date d'inscription   Statut Contributeur Dernière intervention   499
     
    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
    1. titine
       
      je pense pas que ce soit une histoire de pointeur ds ce code
      0
  2. imogen
     
    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