赞
踩
2023年8月5日,周六上午
在C++中,结构体可以继承另一个结构体,就像类继承另一个类一样。这种继承被称为结构体继承。
- #include<iostream>
-
- struct people{
- std::string name;
- int age;
- };
-
- struct student : public people{
- std::string id;
- };
-
- int main(){
- student XiaoMing;
- XiaoMing.age=20;
- XiaoMing.id="202301001";
- XiaoMing.name="小明";
- }
![](https://csdnimg.cn/release/blogv2/dist/pc/img/newCodeMoreWhite.png)
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。