how to count the number of objects created in c++
pls explain with a simple example
Number of objects for what? If you want to count the number of objects of a specific class, you can use a static counter. Something like below.. Increment counter on creation and decrement while destruction..
class A
{
public:
static int counter;
A()
{
counter ++;
}
virtual ~A()
{
counter --;
}
};
int A :: counter = 0;