1 struct和class区别
struct和class
在C++中唯一区别在于 默认访问权限不同
//struct默认权限是公共public
//c1ass默认权限是私有private
#include <iostream>
#include<string>
using namespace std;
//struct和class区别
//struct默认权限是公共public
//c1ass默认权限是私有private
class C1
{
int A;//默认权 私有
};
struct C2
{
int A;//默认权限 公有
};
int main()
{
C1 c1;
// c1.A = 100;//c1ass默认权限是私有,类外不可以访问
C2 c2;
c2.A = 100;//struct默认权限是公共,类外可以访问
return 0;
}
C++类和对象 详细讲解
https://blog.csdn.net/m0_51233386/article/details/116011607
参考:
哔哩哔哩 黑马程序员
2 struct
//typedef 给类型起别名
//结构体 自定义的类型
//关键字 名字 {包含类型的变量};
//struct 名字 {包含类型的变量};//自定义的类型
typedef struct student {
string name;
int age;
string hobby;
}stu1;//在这里起别名的时候,struct前面一定要有typedef
//起别名
typedef student stu2;
int main() {
student zhangsan;
stu1 lisi;
stu2 wangwu;
}