 - #include<iostream>
- 4 F0 f1 l L Q( c% Z
- using namespace std;& {, Q6 A\\" V$ {) P: g
- template<class T>7 ?: Q' ^1 G2 u0 d
- class Sample
- 0 X! k1 r, j9 U. g U\\" w
- {
- 8 G# x+ j2 {) u. J) M
- private:. N0 S& k$ @ _# x' O/ w\\" |8 k) ~
- T n;. _+ P7 m2 g% W h
- public:
- \\" p' c+ ?2 g1 ]( \/ B' m
- Sample():n(0){}) V: V; H' B0 {6 ~- _: S/ \
- Sample(T a):n(a){}
- & Q\\" |) I0 | O# ^# l0 R+ ^
- friend bool operator== (const Sample<T>&,const Sample<T>&);
- ; n' t$ J0 y\\" h( @' A [
- };
- 4 Z8 k* g, m3 O' n8 y
- ) }& ]3 {0 O1 f( [' z+ k
- int main()
- 5 ~/ k% k4 s' M5 f, b
- {2 \& q8 B( N, P
- Sample<int> a(10),b(2);7 N6 T; b2 E+ B- s9 j8 l1 N) c
- if(a==b)cout<<"true";
- 2 V3 W* m0 u7 E% H( d
- else cout<<"false";
- . ?# H& N% x9 b0 x* U
- cout<<endl;( {- ]! g) Z! e
- system("pause");
- - @0 N! U: O; \
- return 0;& s0 w; Q- E3 x! R) t, D& S- q5 D
- }
- + D. v# J\\" e6 ~9 |3 ]) I( I
- template<class T>
- / G0 i1 Q% Y% r6 P# Y/ S) `
- bool operator==(const Sample<T>& a,const Sample<T>& b)
- ) v ]. b6 i4 g+ ?% x$ C+ s
- {
- / A; i6 w# r$ Q2 b
- if(a.n==b.n)6 u4 W2 V& i3 p\\" T6 h8 B. t
- return true;
- 5 V, n! T$ `+ a2 H6 u) R5 ^
- else return false;
- % l\\" ?! [4 W6 r6 F0 z
- }
==用来比较两个数。 |