本文轉自:
http://www.shnenglu.com/tgh621/archive/2008/04/15/47100.aspx?opt=admin
1 #include <stdlib.h> #include <iostream>
2 using namespace std;
3
4 class tgh
5 {
6 public:
7 tgh():i(3){}
8 const int a() const {return 5;}
9 int a(){return i;}
10 protected:
11 int i;
12 private:
13 };
14
15 void main()
16 {
17 const tgh v;
18 tgh s;
19 const int i=s.a();//調用的是int a()
20 int const j=s.a();//調用的是int a()
21 printf("%d,%d",j,i);
22 const int k = v.a();();//調用的是const int a()
23 cout<<k<<endl;
24 system("pause");
25 }
26
27 結果是3,3,5
posted on 2012-04-13 15:01
王海光 閱讀(377)
評論(0) 編輯 收藏 引用 所屬分類:
C++