#include <iostream>
#include <string>
using namespace std;/* In questo programma, tutti gli oggetti dichiarati di classe "MyClass", hanno un attributo (ObjCount) che indica quanti oggetti ci sono di quella classe. Questo perchè l'attributo "ObjCount" è dichiarato come "static".*/
class MyClass
{
static int ObjCount;
string ObjName;
public:
MyClass(string MyName)
{
ObjName = MyName ;
ObjCount++;
cout << "+MyClass -- ObjName = " << ObjName << " -- ObjCount = " << ObjCount << endl;}
~MyClass()
{
ObjCount--;
cout << "-MyClass -- ObjName = " << ObjName << " -- ObjCount = " << ObjCount << endl;}
};
int MyClass::ObjCount = 0;
int main()
{
MyClass x1("x1"), x2("x2"), x3("x3");
} ///:~