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行编译不通过

转载于:https://www.cnblogs.com/hu983/p/5407610.html

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值