Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using operator() in member functions

I overloaded the operator () in one of my classes and I would like to use it in another member function.

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();
};

The line this->operator() does not work. I just want to use the operator I defined as a member function of my class A. The error I get is : Error 1 error C3867: 'A::operator ()': function call missing argument list; use '&A::operator ()' to create a pointer to member

like image 636
vanna Avatar asked Jan 17 '23 04:01

vanna


1 Answers

You should write:

void A::operator()(double x) {
    // stuff with other members and x
    this->operator()();
};

The first () are the name of the operator, and the second are for the call itself: that's the missing (empty) argument list from the error message.

like image 131
rodrigo Avatar answered Jan 26 '23 00:01

rodrigo