 - #include<iostream>9 l& F! ]# l N+ u9 V2 h
- using namespace std;
- : D/ L. E- W5 y
- template<class T>4 T. h/ k( N$ [7 [& r
- class Sample
- % {& Q$ ?$ t/ g5 k; f
- {, E8 k+ V2 D9 i. y4 b$ z
- private:% b+ I: L6 u0 f
- T n;! E8 e7 e. a1 V9 ?
- public:
- 8 s- w) n6 v* p7 l9 S g
- Sample():n(0){}; ]1 V\\" K; [- e* X
- Sample(T a):n(a){}% @, K6 t, `+ _1 n3 m
- friend bool operator== (const Sample<T>&,const Sample<T>&);1 I J$ a$ w, L. ]2 U
- };
- * @3 p+ @; x+ U. c
- % w8 f) i: g& N8 d- e' N7 S
- int main()- ^: t! k* t\\" a7 k
- {
- 4 B. \+ Q( F8 ?( u- `; {; p% d
- Sample<int> a(10),b(2);
- 5 v3 Q8 I) [, u) s
- if(a==b)cout<<"true";
- 5 l# U0 p. Z }
- else cout<<"false";+ k( _7 Z5 s- A
- cout<<endl;5 ]9 \/ @; N$ }6 M
- system("pause");+ I B& g2 I4 O$ a( | F
- return 0;
- 1 W1 b. V. D) F+ x
- }
- + |2 o; T& m: J$ U
- template<class T>3 [$ l: |2 f8 W
- bool operator==(const Sample<T>& a,const Sample<T>& b)* J! Z; c4 A, ^% s1 D) w% N
- {5 O5 ]. {8 R7 ^7 v- b4 V1 r
- if(a.n==b.n)( Y! N\\" a/ @% b- e! u
- return true;
- ; j. c' r: X' q6 E
- else return false;
- 0 Z9 E5 O8 g4 |1 X% A9 _
- }
==用来比较两个数。 |