CHAPTER4-15.cpp
上传用户:fjc899
上传日期:2007-07-03
资源大小:187k
文件大小:1k
- //文件夹名称:CHAPTER4-15
- #include<iostream.h>
- #include<afx.h>
- #include<afxcoll.h>
- class A:public CObject
- {
- int i;
- public:
- A(){}
- A(int n):i(n){}
- int operator!(){return i;}
- void operator+=(int n){i=i+n;}
- };
- void main()
- {
- A *p,*temp;
- CObArray array;
- for(int i=0;i<5;i++)
- {
- p=new A(i);
- array.Add(p);//向数组的末端插入对象指针
- }
- if(!i)temp=p;
- for(i=0;i<5;i++)
- {
- p=(A*)array.GetAt(i);
- if(!i)cout<<"Array item point to "<<p<<" and Local item point to "<<temp<<endl;
- *((A*)array[i])+=1;
- cout<<!*p;
- delete p;//实际对象被删除
- }
- array.RemoveAll();//删除数组内的对象指针
- cout<<flush;
- cin.get();
- }