Is there a way to call automatically function when class created by new
<p>I need to call function whenever class is created using new.
Currently I need to write something like this:</p>

<pre><code>MyClass *myClassPointer = new MyClass(...);
myFunction(myClassPointer);
</code></pre>

<p>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.</p>

<p>I work with quite old framework and myFunction is used for maintenance without breaking it.</p>

<p>edited</p>

<p>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. </p>

<p>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. </p>

<p>Thanks in advance for any ideas and suggestions.</p>

<p>After accept.</p>

<p>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.</p>
