 - #include<iostream>
- 7 m\\" ~6 d# c* y
- using namespace std;
- 0 w2 D' {# K: G0 ?. n. T
- template<class T>
- \\" i8 `2 l9 f% v6 m) L8 ?
- class Sample% Y) O/ C2 v. c9 W/ y: @3 `4 b
- {# b! M: E2 T2 ?\\" v1 J, R. V h
- private:+ B% C1 C, N\\" x/ K& N6 T( C
- T n;
- : |: o\\" N ^( a- A) T/ i
- public:
- 5 F& e9 R) H1 B
- Sample():n(0){}) ^# g; U! o5 o
- Sample(T a):n(a){}
- + s( p6 @# ], ~( u
- friend bool operator== (const Sample<T>&,const Sample<T>&);7 a; N3 G0 ^9 B
- };2 l7 b( q3 y' W- }
- ; o% f( H0 P4 Z. {8 U: {
- int main()1 J6 b: }5 [1 O1 b0 t. E; ]% k
- {
- : J5 [: l, j2 v# c; b4 Z- A
- Sample<int> a(10),b(2);
- % ]& ^; v# E# f
- if(a==b)cout<<"true";, [' j' c4 J. e
- else cout<<"false";# d2 i* V3 ]8 L1 k
- cout<<endl;4 |- n! r: b6 {
- system("pause");
- 7 V$ I$ ~$ g6 ?; l# U% Z
- return 0;
- 3 w- m7 g+ |9 u1 U( p% P/ G( C/ i
- }+ k8 j& f* L# |' A4 @: a9 G( ?
- template<class T>\\" Y9 O# o4 ~3 h+ j+ x
- bool operator==(const Sample<T>& a,const Sample<T>& b)& v+ e' i# o5 w3 a# @% T
- {3 i( N' A# }) c1 |4 `3 |2 ]5 `0 \
- if(a.n==b.n)2 W. d! q6 A9 v1 X( N1 F1 |# K
- return true;# G1 W/ n% F; Y Z
- else return false;. y# y* J a b) B. U
- }
==用来比较两个数。 |