fonctions amies (compilation)
Bonjour à tous !
Je désire créer une classe en redéfinissant l'opérateur d'addition. Je mets donc ceci dans le .h :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
|
#include <list>
#include <sstream>
using namespace std;
class BigInt
{
public:
BigInt();
BigInt(const int& n);
virtual ~BigInt();
BigInt& operator =(const int& n);
bool operator >(const int& n);
bool operator >(const BigInt& bi);
friend BigInt operator+(const BigInt& a, const BigInt& b);
private:
list<int> nombre;
}; |
et dans le .cpp :
Code:
1 2 3 4 5 6 7 8 9
| BigInt operator+(const BigInt& a, const BigInt& b)
{
BigInt res;
list<int>::const_reverse_iterator it1 = a.nombre.rbegin();
list<int>::const_reverse_iterator it2 = b.nombre.rbegin();
return res;
} |
Lors de la compilation, j'ai l'erreur suivante :
Code:
1 2
| D:\mfc\fichusnombres\BigInt.cpp(74) : error C2248: 'nombre' : cannot access private member declared in class 'BigInt'
D:\mfc\fichusnombres\BigInt.h(21) : see declaration of 'nombre' |
Pourtant la fonction est bien déclarée comme amie... que faire ?