Valhalla Legends Forums Archive | C/C++ Programming | [C++]Operator overloading

AuthorMessageTime
shout
In a recent post by MyndFyre, he told someone to overload the << and >> to make a buffer look cool. I did this, but now I have a problem.

If I do something like:
[code]
*buff << dwval;
[/code]
it works. But:
[code]
*buff << dwval1 << dwval2;
[/code]
gives me a
[code]
error C2296: '<<' : illegal, left operand has type 'Buffer *' bufftest.cpp 130
[/code]

This is my first venture into C++ operator overloading :/
December 10, 2005, 10:17 PM
Kp
You're probably returning the wrong type in your operator<<.  You should return *this.
December 10, 2005, 10:27 PM
shout
Yes, that worked. I was returning a pointer to the class. I see my error now.
December 10, 2005, 10:57 PM
Myndfyr
[quote author=Shout link=topic=13476.msg137119#msg137119 date=1134253073]
In a recent post by MyndFyre, he told someone to overload the << and >> to make a buffer look cool. I did this, but now I have a problem.
[/quote]
Thanks for trying to blame me!  :P
December 11, 2005, 1:48 AM
shout
[quote author=MyndFyre link=topic=13476.msg137147#msg137147 date=1134265734]
[quote author=Shout link=topic=13476.msg137119#msg137119 date=1134253073]
In a recent post by MyndFyre, he told someone to overload the << and >> to make a buffer look cool. I did this, but now I have a problem.
[/quote]
Thanks for trying to blame me! :P
[/quote]
Welcome :)
December 11, 2005, 7:50 AM

Search