类能报告对象的创建、销毁、赋值以及每个对象一个识别号(代码来源于C++沉思录) #include <iostream>class Test{ public:Test();Test(const Test&);Test& operator=(const Test&);~Test(); private:static int count;int id; };int Test::count = 0; Test::Test(){id = ++count;std::cout << "Test " << id<< " default constructor\n"; } Test::Test(const Test& t){id = ++count;std:: cout << "Test " << id<< " copied from " << t.id << std::endl; } Test& Test:: operator=(const Test& t){std:: cout << "Test " << id<< " assigned from " << t.id << std::endl; } Test::~Test(){std::cout << "Test " << id << " destroyed" << std::endl; }int main() {Test s;Test t(s);s = t;return 0; }