类和对象-封装-C++中class和struct的区别

  • class和struct的区别

 

点击查看代码
#include<iostream>
#include<string>

using namespace std;
//struct和class区别
//struct 默认权限是 公共public
//class  默认权限是 私有private

class A
{
	int a; //默认权限是 私有private
};

struct B
{
	int b; //默认权限是 公共public
};

int main(){

	A a1;
	//a1.a = 1; //Error:成员"A:a"(已声明所在行数: 11)不可访问

	B b1;
	b1.b = 1;


	system("pause");

	return 0;
}

 

posted @ 2021-07-19 15:05  毋纵年华  阅读(51)  评论(0)    收藏  举报