van*_*nna 4 c++ operator-overloading
我在我的一个类中重载了operator(),我想在另一个成员函数中使用它.
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();
};
Run Code Online (Sandbox Code Playgroud)
这条线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()();
};
Run Code Online (Sandbox Code Playgroud)
第一个()是运算符的名称,第二个是调用本身的名称:这是错误消息中缺少的(空)参数列表.
| 归档时间: |
|
| 查看次数: |
195 次 |
| 最近记录: |