 - #include<iostream>
- ; X+ G9 Z; j; e
- using namespace std;
- 5 h2 V\\" J$ S5 l1 o/ G v/ K
- template<class T>9 D9 P* O$ W, T0 @
- class Sample6 l# T% R9 J5 _. |
- {: G, Z9 w; o* W/ X\\" G; X
- private:; y. _0 Z# |* x9 T* K
- T n;: T. |. A; m! E# f! g
- public:
- . [$ O0 _! ^6 Z\\" C) f# ]
- Sample():n(0){}
- 0 ^) s9 ?; { A* X9 O( T
- Sample(T a):n(a){}
- % B6 [8 L7 O: ~$ C4 s5 w0 y6 E! J
- friend bool operator== (const Sample<T>&,const Sample<T>&);
- 3 X9 x\\" v; S\\" N
- };. y6 C8 |/ h: a
- & S2 V/ ~% A2 B0 o
- int main()
- s7 t( N\\" s, C% L7 f0 ~9 m0 W/ M D
- {4 e9 o0 [9 Q6 k
- Sample<int> a(10),b(2);& I2 e9 | k5 Y/ e' e- |* D
- if(a==b)cout<<"true";
- 7 P# q' R' `& D. ^ X
- else cout<<"false";
- - x& {/ E5 s | n; ], d
- cout<<endl;3 V0 E2 x' _* F |1 L
- system("pause");* j1 P! Y# T# G/ ?+ y' u3 e, j0 N
- return 0;$ [ D# H5 e2 Y& F. s$ k7 v
- }
- 4 S2 c' x# g8 |% ~% h* }' T# G% X
- template<class T>
- 4 h# Z( g9 h8 F$ }6 N
- bool operator==(const Sample<T>& a,const Sample<T>& b)& O ]9 l6 X6 T4 @
- {
- 3 e\\" ~' k* g# N
- if(a.n==b.n)% I0 h: }% F( X+ T* Y& D* N
- return true;
- ! E1 w$ y: v; G\\" ?
- else return false;% O: M' _ @( I+ \) q0 G9 b3 Y6 u
- }
==用来比较两个数。 |