本文转自:
http://www.cppblog.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
王海光 阅读(374)
评论(0) 编辑 收藏 引用 所属分类:
C++