#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;}
1 回答
慕容708150
TA贡献1831条经验 获得超4个赞
for_each(member.begin(),member.end(),outCMyClass);这一句有问题
因为这个函数一定要传一个参数的。
- 1 回答
- 0 关注
- 103 浏览
添加回答
举报
0/150
提交
取消