C++访问声明

代码:

 1 #include <iostream> 
 2 #include <string>
 3 
 4 using namespace std; 
 5 
 6 struct B{
 7     private:
 8         int s;
 9     public:
10         B(int j){
11             s = j;
12         }
13         void print(){
14             cout<<s<<endl;
15         }
16 };
17 
18 struct C:private B{
19     private:
20         char c;
21     public:
22         using B::print;
23         C(int j,char d):B(j){
24             c = d;
25         }
26 };
27 
28 int main(){
29 
30     B b(123);
31     C c(13,'k');
32     c.print();
33 
34     return 0;
35 }

 

输出:

13

分析:

假如注释掉22行,则 32行编译不通过

posted @ 2016-04-19 11:56  hu983  阅读(191)  评论(0编辑  收藏  举报