Conting of objects created in stack and heap for many classes

Posted by viswanathan on Stack Overflow See other posts from Stack Overflow or by viswanathan
Published on 2010-06-09T10:27:38Z Indexed on 2010/06/09 10:32 UTC
Read the original article Hit count: 210

Filed under:

What is the best way to count the total number of objects created in both stack and heap for different classes. I know that in C++ new and delete operators can be overloaded and hence in the default constructor and destructor the object count can be incremented or decremented as and when the objects get created or destroyed.

Further if i am to extend the same thing for object counting of objects of different classes, then i can create a dummy class and write the object count code in that class and then when i create any new class i can derive it from the Dummy class.

Is there any other optimal solution to the same problem.

© Stack Overflow or respective owner

Related posts about c++