Code, Notes

C++ – Calling Overloaded Operator () from Pointer

Here are three ways to call a C++ classes’ operator () using a pointer:
Say you have a C++ class name MyClass that overloads the operator “()”, something along the lines:

Class MyClass{
  void operator()(int a, double b);
MyClass* theClass = new MyClass;

// method 1: use a reference
MyClass& classRef = *theClass;
classRef(a, b);

// method 2: dereference in place

// method 3: dereference the ugly way:

I use method 2.

Leave a Reply

Your email address will not be published. Required fields are marked *