Ok, I can’t get this code work:
I want to concatenate my custom manipulators.
so they will be called like cout << endl is called.
for example I want this:
emit << event1 << event2 << event3;
here is my code:
class Emit
{
public:
// ...
const void operator<<(const Event& _event) const;
}const emit; // note this global
inline const void Emit::operator<<(const Event& _event) const
{
Start(_event);
}
class Event
{
// ...
const Event& Event::operator<<(const Event& _event) const;
};
inline const Event& Event::operator<<(const Event& _event) const
{
return _event;
}
However I cant call this:
emit << event1 << event2 << event3;
I’m eather receiving compile time error, link time errors and what ever I change in my code I get coresponding error no success.
for example this one:
Error 1 error C2679: binary ‘<<‘ : no operator found which takes a
right-hand operand of type ‘const EventHandling::Event’ (or there is
no acceptable conversion) c:\users\admin\documents\visual studio
2010\projects\cppsystem\eventhandling\test.h 18
thanks alot.
Those operators are called from left to right. As such, the first call (
emit << event1) must return a reference toEmit:And now you don’t need to overload
operator<<in yourEventclass anymore.