 - #include<iostream>
- 1 y; w' y\\" L% K\\" m6 x& r
- using namespace std;; G3 ]2 m- O5 P9 [
- template<class T>
- - m9 N5 D T+ [1 _# u5 A3 Q
- class Sample
- $ i+ {1 y\\" m\\" q
- {5 h1 {6 R Y% R: r1 b: ?
- private:
- : G8 U! r0 z9 J( o* s
- T n;+ D) B- s0 F* ?& }) e
- public:% Z\\" {; w2 t4 I( V) q: {% _
- Sample():n(0){}
- \\" H9 e) g- @2 H: _, u& p# J, S3 \/ p- C
- Sample(T a):n(a){}
- ' b6 O; {3 w. B5 c2 u5 \* l
- friend bool operator== (const Sample<T>&,const Sample<T>&);
- * G l% h$ w8 b1 e% E\\" H+ k\\" a+ P
- };
- V+ C! F9 L) C: g K& r
- 8 r9 F A: ~6 e+ X* n4 I
- int main()
- / H5 y5 I6 D$ e/ J4 h7 X9 Y4 |! s
- {
- \\" c7 P3 o6 E9 b4 t* @
- Sample<int> a(10),b(2);; U4 G8 f' L: l' y
- if(a==b)cout<<"true";
- - g; H7 d5 s$ a8 u% S6 Z
- else cout<<"false";
- % }/ W- Q; m. n3 K# ?
- cout<<endl;( b3 S3 p4 ~3 w) n% O6 U% u4 T
- system("pause");- m' G$ y* f0 a, P. I
- return 0;
- 2 Q% ^7 N6 }. L6 Z: X( m
- }
- 7 Z n( y( F8 O+ C4 E6 ]0 [
- template<class T>4 x/ z\\" v6 X8 h( e. N) T. d
- bool operator==(const Sample<T>& a,const Sample<T>& b)' \% H/ t2 t' S: G
- {; [0 w. a% t7 ^* P
- if(a.n==b.n)
- % c+ D+ o4 e* ]\\" \
- return true;
- F7 V' X* A* R
- else return false;
- + f0 w7 V- b; @
- }
==用来比较两个数。 |