I need to call function whenever class is created using new.
Currently I need to write something like this:
MyClass *myClassPointer = new MyClass(...);
myFunction(myClassPointer);
When MyClass is created as local object myFunction cannot be called. MyClass have at lest 2 constructors with different arguments. Is there a way to automatize it, that other programmers didn’t need to remember to call it.
I work with quite old framework and myFunction is used for maintenance without breaking it.
edited
myFunction is a public member function of application main window, witch is visible in all code of application. But myFunction my be moved out of class mainWindow and be changed into global function if it is needed.
I was thinking of some kind of macro in header file of myClass, because this way I don’t need to inspect all code that is already written, and add those modifications. But I couldn’t find any solution.
Thanks in advance for any ideas and suggestions.
After accept.
The problem is because of bad design of MyClass and it’s use in framework. I accepted Mark’s answer, because MyClass should be created by ClassFactory from the start.
Use a class factory rather than calling
newdirectly. The factory can callmyFunctionbefore returning the pointer.