 - #include<iostream>5 X: r1 T& R+ Y8 S% [/ V
- using namespace std;, J* l% {7 T/ S, E\\" b
- template<class T>
- ; Z$ ?: K- d1 U) ?) C3 j: D+ ^- I
- class Sample2 y/ @) f2 D* F+ P& m\\" t
- {
- 1 S* p1 [2 X\\" ]$ E
- private:$ u: F2 ]; }; @2 B0 M+ D* ~
- T n;
- % \2 J: u1 |: |! u2 |9 ^% I
- public:\\" V' k. G& @$ ?2 q' U
- Sample():n(0){}& C1 E9 R j0 I# B- |
- Sample(T a):n(a){}
- 9 Q7 G4 T9 d$ x1 E\\" c# u
- friend bool operator== (const Sample<T>&,const Sample<T>&);, `5 `( P5 i( B$ N' d
- };+ X4 F0 J4 M6 r; x
- $ \: z+ L! n, m# e6 m6 k0 S
- int main()2 `- _' v+ ?) g) J0 V% ~\\" |
- {
- # W9 H* y7 V8 \# t
- Sample<int> a(10),b(2);
- ! _0 Q3 `# j b8 H
- if(a==b)cout<<"true";5 T- ~; T! z0 h# s1 p; @- |
- else cout<<"false";
- * b* |1 o7 E& h( x- C7 t& |
- cout<<endl;6 A/ W4 M- g( R\\" M7 [! l8 Z
- system("pause");. d/ p- x6 X( \& b
- return 0;
- ( ~: G4 J% J2 W/ h% q
- }& c t6 i3 f\\" ~8 p0 B4 ^
- template<class T>
- ! q' j# g1 C8 J; ]\\" z& A- f
- bool operator==(const Sample<T>& a,const Sample<T>& b)/ W2 ~# O& w; x9 q\\" y, Z
- {
- ( f- c# n5 x( f- E\\" X
- if(a.n==b.n)5 U* f3 r\\" v9 {5 r\\" r' x4 b\\" J* `& I
- return true;
- 0 P L5 J1 g3 h
- else return false;
- $ }0 Z! M/ t: w2 N, o
- }
==用来比较两个数。 |