Consider the following:
class MyClass {
public:
int operator ()(int a, int b);
};
When having:
MyClass* m = new MyClass();
I want to access the operator()
method, so I could:
(*m)(1,2);
But can I do this?
m->(1,2);
Consider the following:
class MyClass {
public:
int operator ()(int a, int b);
};
When having:
MyClass* m = new MyClass();
I want to access the operator()
method, so I could:
(*m)(1,2);
But can I do this?
m->(1,2);
Not with that syntax, but you can do
m->operator()(1,2);
If you won't change m
(what it points to), you can substitute (*m)
by a reference:
MyClass *m = new MyClass();
MyClass &r = *m;
r(1, 2);
See this answer for more details.