 - #include<iostream>1 s& ^# B6 q1 N. |
- using namespace std;/ N5 `' {4 U* w% M$ I
- template<class T>' @! V- v* l7 y
- class Sample: x- l( S _. e. c( Q( n
- {$ z+ G# M. B- r+ C; U t' y
- private:
- : K8 L6 }/ f% l. O: e
- T n;8 }! g& F& F$ c# c2 j' y
- public:
- \\" I9 ^\\" a8 ^: P, b, [ n; w0 p
- Sample():n(0){}
- * f D6 E4 h% ~
- Sample(T a):n(a){}
- . _+ f4 Z6 Q y2 M$ Q
- friend bool operator== (const Sample<T>&,const Sample<T>&);
- 8 h* \* R% J- T1 i) {9 o; a+ z
- };
- # z; E$ r6 n, E- p0 T
- M) y! L# h9 U: \
- int main()
- ' j$ t\\" Z( o( T3 }! ?3 G9 s$ r
- {4 x7 d2 Q y$ b0 Q5 M
- Sample<int> a(10),b(2);: z% K: E3 s7 c
- if(a==b)cout<<"true";
- ) w+ p* ?& W\\" T1 @* ?' i7 H
- else cout<<"false";0 n% M3 M0 n6 K5 B4 a0 w
- cout<<endl;; I) l! B- x; G, {* q' e: h; g
- system("pause");' h/ d0 s9 }( R8 x, i
- return 0;
- ) k2 q0 D0 u2 C9 T$ r
- }
- 0 d- S9 {, v8 t. Y! r
- template<class T>5 T( {) v. S( N) U+ i
- bool operator==(const Sample<T>& a,const Sample<T>& b)) W: O. n5 E2 ]' P0 W
- {
- 4 K2 _- `4 ~- d\\" a
- if(a.n==b.n), B {2 X# K. i. F6 P
- return true;1 d, [& I2 ]/ Y& `1 `% m. q1 X
- else return false;4 @* l4 M0 {7 _* g7 [) f
- }
==用来比较两个数。 |