我在我的一个类中重载了运算符 (),我想在另一个成员函数中使用它。
class A {
public:
void operator()();
void operator()(double x);
};
void A::operator()() {
// stuff
};
void A::operator()(double x) {
// stuff with other members and x
this->operator();
};
this->operator()
行不起作用。我只想使用我定义为我的类 A
的成员函数的运算符。我得到的错误是:Error 1 error C3867: 'A::operator ()': function call missing argument list; use '&A::operator ()' to create a pointer to member
最佳答案
你应该写:
void A::operator()(double x) {
// stuff with other members and x
this->operator()();
};
第一个
()
是运算符的名称,第二个是调用本身:这是错误消息中缺少的(空的)参数列表。