[operator] probleme seulement sous linux gcc 4.4.6
Bonjour
j'aimerais trouver une solution au problème suivant
en effet je peux pas changer de compilateur et j'ai fait des test avec visual studio (avec le même code) et ça passe
bref j'ai une classe :
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
|
class Zota {
float value;
public:
float getValue() {
return this->value;
}
explicit Zota(float value) :
value(value) {
}
virtual Zota operator+(Zota &ob) {
return Zota(this->getValue() + ob.getValue());
}
virtual Zota operator+(double ob) {
return Zota(this->getValue() + ob);
}
virtual Zota operator*(Zota &ob) {
return Zota(this->getValue() * ob.getValue());
}
virtual string toString() {
return to_string((long long)this->value);
}
}; |
et j'execute le code suivant
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 25 26 27 28 29
|
cout << endl << "* test beta (ref)" << endl;
Zota a(2);
Zota b(3);
Zota c(5);
{
Zota d = a + b + c;
cout << " a + b + c = " << d.toString() << endl;
}
{
Zota d = a + 10;
cout << " a + 10 = " << d.toString() << endl;
}
// {
// Zota d = 11 + a;
// cout << " 11 + a = " << d.toString() << endl;
// }
{
Zota d = a * b;
cout << " a * b = " << d.toString() << endl;
}
{
Zota d = (a * b) + c; // CA PASSE
cout << " (a * b) + c = " << d.toString() << endl;
}
{
Zota d = c + (a * b); // CA COMPILE PAS
cout << " c + (a * b) = " << d.toString() << endl;
} |
bref (a * b) + c ca passe et
c + (a *b) ca compile pas avec l'erreur suivante :
error: no match for ‘operator+’ in ‘c + Zota::operator*(((Zota&)(& b)))’
si vous avez une idée de la solution possible
merci