J
jseb
Hello,
I thought i had understood operator overloading.
Look the small code below.
It should not print "same amount" when comparing "Me" and "You", but
that's what i get.
Could you tell me where i'm wrong, please ? Thank you.
#include <iostream>
class Foo {
private:
int gold;
public:
Foo(int gold) { this->gold = gold; }
~Foo() {}
bool operator== (const Foo &);
};
bool Foo:
perator== (const Foo &other)
{
std::cout << ". = " << gold << "; .other = " << other.gold << "\n";
if (other.gold==gold) return true;
}
int main(void)
{
Foo Me(42);
Foo You(33);
if (Me==You) std::cout << "same amount\n";
return 0;
}
I thought i had understood operator overloading.
Look the small code below.
It should not print "same amount" when comparing "Me" and "You", but
that's what i get.
Could you tell me where i'm wrong, please ? Thank you.
#include <iostream>
class Foo {
private:
int gold;
public:
Foo(int gold) { this->gold = gold; }
~Foo() {}
bool operator== (const Foo &);
};
bool Foo:
{
std::cout << ". = " << gold << "; .other = " << other.gold << "\n";
if (other.gold==gold) return true;
}
int main(void)
{
Foo Me(42);
Foo You(33);
if (Me==You) std::cout << "same amount\n";
return 0;
}