【发布时间】:2012-01-06 22:34:12
【问题描述】:
好的,我无法让这段代码工作:
我想连接我的自定义操纵器。
所以他们会像cout << endl一样被调用。
例如我想要这个:
emit << event1 << event2 << event3;
这是我的代码:
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;
}
但是我不能这样称呼:
emit << event1 << event2 << event3;
我收到编译时错误、链接时错误以及我在代码中所做的任何更改都会收到相应的错误,但没有成功。
例如这个:
错误 1 错误 C2679: 二进制 '
非常感谢。
【问题讨论】:
标签: c++ overloading operator-keyword