Reputation: 453
I have a member function which needs to call operator() on the class instance (this), and I could not guess at the right syntax. I tried
this();
*this();
this->();
this->operator();
and a few other things, but the error messages are not very informative, so I dont know what am I doing wrong.
The closest I found on SE: How do I call a templatized operator()()?
Upvotes: 9
Views: 3445
Reputation: 453
Use
this->operator()();
Explanation:
Upvotes: 16
Reputation: 465
I propose an example (test method):
#include <iostream>
class A
{
public:
int operator()(int index)
{
return index + 1;
}
int test()
{
// call to operator ()
return this->operator()(5);
}
};
int main()
{
A obj;
std::cout << obj.test() << std::endl;
std::cout << obj(7) << std::endl;
std::cout << obj.operator()(9) << std::endl;
}
Upvotes: 5