C++中的struct与class继承方式

代码:

1 #include <iostream>
 2 #include <cstdio>
 3 
 4 using namespace std;
 5 
 6 //class A{
 7 struct A{
 8     public:
 9         int i{5};
10         void print(){
11             cout<<i<<endl;
12         }
13 };
14 //class B:A{
15 struct B:A{
16     public:
17 };
18 
19 int main(){
20 
21     B b;
22     b.print();
23 
24     return 0;
25 }

输出:

5

分析:

C++中struct默认继承方式为public,而class为private。
原文链接: https://www.cnblogs.com/hu983/p/5521237.html

欢迎关注

微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍

原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/233806

非原创文章文中已经注明原地址,如有侵权,联系删除

关注公众号【高性能架构探索】,第一时间获取最新文章

转载文章受原作者版权保护。转载请注明原作者出处!

(0)
上一篇 2023年2月13日 下午4:02
下一篇 2023年2月13日 下午4:02

相关推荐