 - #include<iostream>
- # P' _/ s9 |6 Z! C. `$ m
- using namespace std;7 l3 `/ q, \5 R
- template<class T>
- 1 a4 n6 m9 b! n9 P, K( t
- class Sample
- $ F6 \9 w7 u! z* G! w) h' Y8 t
- {
- , \% u% m8 W7 H
- private:1 U5 s; S- n9 M: Q6 ]% h, E
- T n;2 E; e8 h! p9 r. j# P) |5 m; s& c- }; @
- public:
- 7 i4 F* C s$ \ B
- Sample():n(0){}0 u! e0 A) l' m& Y8 @3 P
- Sample(T a):n(a){}
- ) j/ y9 }/ t6 {
- friend bool operator== (const Sample<T>&,const Sample<T>&);3 F5 ~, t9 E1 f& w2 |7 A9 o
- };
- ; Q0 e* w* N5 h7 {8 H5 q( @2 j\\" c. Y
- + U- G1 u7 h6 N
- int main()+ a% b0 c: b3 ], }4 D, O4 P
- {
- 5 l( C* @6 K- Z
- Sample<int> a(10),b(2);
- & T( } m4 N' T0 _) m% C9 K( W2 _
- if(a==b)cout<<"true";
- \\" N( w\\" N' Y: t# H; D
- else cout<<"false";
- 4 V3 U S! V) {/ y( |
- cout<<endl;
- 5 Q; M2 f2 k; @/ |
- system("pause");9 M6 B/ k g, V8 l
- return 0;
- }) l5 g! j/ g; Q1 O
- }) \ d' S+ d7 _\\" r! C) g/ e6 C
- template<class T>
- / f$ v# g\\" T m$ I
- bool operator==(const Sample<T>& a,const Sample<T>& b)
- ) |' G9 b* y; o. W9 y& Q9 e9 _ M& @
- {
- & J3 K8 J9 y' G6 n9 {# w* E& N
- if(a.n==b.n)
- % b6 ^- ~! v6 P2 j* |
- return true;- Y6 R$ b. L) l& s. e
- else return false;- d4 E! F- K& \( A0 B- S& `
- }
==用来比较两个数。 |