 - #include<iostream> ]/ _8 |0 l0 l5 |0 [7 T [2 V( ]; ~
- using namespace std;3 C) t( \- c% B& h) J5 V
- template<class T>( i, a+ v# S% u2 Y9 A4 [\\" x0 @( K
- class Sample
- 6 ^6 W$ |8 C. s- V4 W8 l3 w8 g
- {! o2 [. t+ q1 ]. x, \' C; K& I
- private:& d! J/ ^, K8 \9 _( ?, O
- T n;4 R/ _) _, {: i: O9 h4 S, |% ?
- public:1 f7 G' t- D4 C+ n6 ^8 A$ x& n
- Sample():n(0){}
- 7 r- _* b+ u4 C6 K
- Sample(T a):n(a){}8 _ y! v3 `5 M, J9 X
- friend bool operator== (const Sample<T>&,const Sample<T>&);
- $ m$ t; S; ?' m5 @
- };
- ; J\\" K, ]% W% M- j/ X
- & J) R, B9 T% J# j
- int main()
- ' k$ I1 C8 j0 V% z7 h
- {
- 8 e7 }- Z0 a. X7 l
- Sample<int> a(10),b(2);
- ! I0 u4 P7 `\\" K% m8 ~0 s
- if(a==b)cout<<"true";
- * X7 [' B* q O$ J2 \' t+ L; l
- else cout<<"false";# J# b7 i @4 m6 t+ A& S; @
- cout<<endl;
- 2 U }! Z9 y$ E4 B; C
- system("pause");3 y q5 `* q! Q. }' S/ x
- return 0;
- 2 {* b7 n' A' h X6 x1 V$ C% F5 r
- }. ~* S& I2 U& J3 j: l% D$ `/ r
- template<class T>
- + }; x, |: M8 I' a( W\\" _$ g- P8 l
- bool operator==(const Sample<T>& a,const Sample<T>& b)/ M\\" d+ G4 M. r
- {0 ^& W% f3 G# a3 ~7 S
- if(a.n==b.n), F C8 _4 V; t5 W: p
- return true;
- 0 @* U/ Z& Z0 w1 ]
- else return false;- @. f% N) t: I3 i/ m
- }
==用来比较两个数。 |