 - #include<iostream>+ |6 y, P# s\\" Y% E
- using namespace std;2 Q' |6 r$ Y% C* J1 ], D
- template<class T>
- 9 g0 S, k! [- \# s& M0 x
- class Sample
- 5 R2 c. p$ T K. e+ L
- {
- $ r4 ]\\" H- w6 ]: c8 Y4 k) Y {
- private:
- 8 L; o! c1 K7 X. ?. J
- T n;
- 1 m\\" I$ Z G2 }* b; T% ^0 W9 c
- public:
- 5 D p& p4 ?4 r3 O: G! Q, \& M0 d# C
- Sample():n(0){}
- & @$ L: o- t5 P4 S
- Sample(T a):n(a){}
- , s y& C, y: Y
- friend bool operator== (const Sample<T>&,const Sample<T>&);
- + {1 b; ~\\" x- D) Q
- };; M8 v7 ~0 u# i
- + {8 T8 p+ |$ ^) Y( u/ I
- int main()
- 3 t! h4 h2 ^0 l% x& [6 g) s
- {
- ) u$ N$ z: ?# i8 k; E/ y! I+ z7 e/ ?/ {
- Sample<int> a(10),b(2);. u) m, k8 Z% y& r* h8 S$ i
- if(a==b)cout<<"true";
- ! t/ K7 E: f* u7 j3 ]. f
- else cout<<"false";/ d& T7 D2 V; c5 p
- cout<<endl;
- $ y$ f; h& S5 S2 H+ w5 N |+ k
- system("pause");: `\\" s) g# u0 u/ F5 O5 B* o
- return 0;5 q4 _$ ~) B1 D
- }$ d$ W s. d9 m3 d
- template<class T>\\" ]% r8 h+ W' \7 i6 N0 F$ C
- bool operator==(const Sample<T>& a,const Sample<T>& b)* `. i3 S1 h4 l2 ]
- {6 D+ |2 _- f( b\\" f
- if(a.n==b.n)& i; j3 ~, E. s
- return true;$ e7 h) K0 T) O/ O6 [
- else return false;/ E3 ~ w3 r q
- }
==用来比较两个数。 |