Reputation: 16845
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);
Upvotes: 47
Views: 24713
Reputation: 509
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.
Upvotes: 8
Reputation: 258618
Not with that syntax, but you can do
m->operator()(1,2);
Upvotes: 80