Problème surcharge opérateur
Bonjour,
Mon problème est assez simple. J'aimerais juste faire une surcharge de l'opérateur de flux << mais malgré quelques recherches sur google, j'ai pas vraiment compris comment l'implémenter correctement.
Je reçois cette erreur à la compilation :
error: 'std::ostream& BigInt::operator<<(std::ostream&, const BigInt&)' must take exactly one argument
Du code parle plus que des mots ^^
Fichier .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 24
|
#ifndef INCLUDE_ME
#define INCLUDE_ME
#include <iostream>
#include <vector>
using namespace std;
class BigInt
{
private:
vector<int> number;
public:
// Constructeurs
BigInt(int number);
BigInt(string number);
// Operators
ostream& operator<<(ostream& flux, const BigInt& bigNumber);
};
#endif |
Fichier .CPP
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
|
#include "BigInt.h"
// Constructeurs
BigInt::BigInt(int number)
{
this->number[0] = number;
}
BigInt::BigInt(string number)
{
for (int i = 0; i < number.size(); i++)
{
this->number.push_back((int)number[i]);
}
}
// Operators
ostream& BigInt::operator<<(ostream& flux, const BigInt& bigNumber)
{
//return flux;
} |
Ce qui me semblait bizarre c'est que je met ma définition de méthode en public :? !
Je peux pas en dire plus juste ce petit détail que je trouve bizarre :S !
Merci d'avance pour votre aide !
Remerciement (autre moyen)
Merci pour ta réponse ça marche ! :D
J'ai modifié ma définition en global amis de BigInt et aussi j'ai du modifier l'implémentation de ma méthode en enlevant le BigInt:: de ma méthode.
Mais ça m'interpelle :S
Est-ce la seul solution possible où existe-t-il une autre solution ?
J'espère que j'aurais réponse à ma question ^^
Merci pour ta solution kessoufi ;)
Fichier .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 24
|
#ifndef INCLUDE_ME
#define INCLUDE_ME
#include <iostream>
#include <vector>
using namespace std;
class BigInt
{
// Operators
friend ostream& operator<<(ostream& flux, const BigInt& bigNumber);
private:
vector<int> number;
public:
// Constructeurs
BigInt(int number);
BigInt(string number);
};
#endif |
Fichier .CPP
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
|
#include "BigInt.h"
// Constructeurs
BigInt::BigInt(int number)
{
this->number[0] = number;
}
BigInt::BigInt(string number)
{
for (int i = 0; i < number.size(); i++)
{
this->number.push_back((int)number[i]);
}
}
// Operators
ostream& operator<<(ostream& flux, const BigInt& bigNumber)
{
//return flux;
} |