- //文件名:CHAPTER3-11.cpp
- #include<iostream.h>
- class A
- { int j;
- public:
- A(){}
- A(int x):j(x){}
- A(A *x){j=x->j;}
- void operator!(){cout<<"J="<<j<<endl;}
- };
- template<class T>
- class B
- { int i;
- T *x;
- public:
- B(int xa,T *p):i(xa){x=new T(p);}
- void operator!(){cout<<"I="<<i<<endl;!*x;}
- };
- void main()
- {
- A a(1); //最后的显示结果为:
- B<A> b(2,&a); //I=2
- !b; //J=1
- }