 - #include<iostream> W) |0 L: c5 D v4 y0 z
- using namespace std;) Q% {/ Y) G! B J0 @3 c3 i
- template<class T>
- % A. f/ z3 m% ^
- class Sample
- . w, R$ G% S- u
- {/ m5 D s/ ^8 N! I' A# Y
- private:
- i( o4 ^6 f$ {1 V- |2 y, o
- T n;\\" f k: q\\" Z5 J\\" O7 n\\" ?- A8 X& M
- public:
- s6 j2 m7 f0 J6 O3 S5 i
- Sample():n(0){}9 Y5 f' N# A6 M/ s; {8 D/ j
- Sample(T a):n(a){}
- 0 E3 w\\" x( L* W! v1 U6 g
- friend bool operator== (const Sample<T>&,const Sample<T>&);
- # {8 Y8 b! h! r- l6 W& Y
- };
- . f d8 X: \9 c# S! }1 l
- ; b: w$ d* ~4 A& A! j5 z
- int main()
- K% s4 T9 F: x9 `/ ^
- {* F3 w+ x+ V, y! u. o; H
- Sample<int> a(10),b(2);
- T5 y1 |2 Q- J- B1 t- S4 B4 k# u
- if(a==b)cout<<"true";
- * w% M, i1 \+ \# G/ F
- else cout<<"false";
- $ ?0 G4 }- W% c3 x
- cout<<endl;2 Q$ Z7 M. V4 q' c2 N
- system("pause");* B0 K& }' i2 F+ U
- return 0;
- B& ^! d2 ~/ V$ q
- }
- \\" U5 |# s N# f6 L
- template<class T>% Z4 R' K6 ]1 S
- bool operator==(const Sample<T>& a,const Sample<T>& b)1 _1 Y) V& a' ~3 D! r
- {
- O2 ]' s: w( @' F
- if(a.n==b.n)
- # ~: `5 S* f4 {4 P9 `, l
- return true;
- ' ~* i5 E$ R* }
- else return false;5 ~8 @# D* b. l0 x5 d( V
- }
==用来比较两个数。 |