#include <iostream>
#include <vector>
#include <iterator>
#include <algorithm>
using namespace std;
class CMyClass
{
private:
int m_nValue;
public:
static vector<CMyClass>member;
CMyClass();
CMyClass(int value);
~CMyClass();
static void ShowList();
friend ostream & operator<<(ostream & output,const CMyClass & temp);
void outCMyClass(const CMyClass& temp){ cout << temp << endl; }
};
int main()
{
CMyClass a(100);
CMyClass b(1);
CMyClass c;
CMyClass *d = new CMyClass;
*d = 10;
cout << "The first end: " << endl;
CMyClass::ShowList();
if (1)
{
CMyClass e(1000);
cout << "The second end: " << endl;
CMyClass::ShowList();
}
delete d;
cout << "The third end: " << endl;
CMyClass::ShowList();
return 0;
}
CMyClass::CMyClass()
{
m_nValue = 0;
member.push_back(*this);
}
CMyClass::CMyClass(int value)
{
m_nValue = value;
member.push_back(*this);
}
CMyClass::~CMyClass()
{
member.pop_back();
}
void CMyClass::ShowList()
{
for_each(member.begin(),member.end(),outCMyClass);
}
ostream & operator<<(ostream & output, const CMyClass & temp)
{
output << temp.m_nValue;
return output;
}
慕容708150
相关分类