C++基礎(八)struct和class的區別

we1less發表於2020-09-25

class    預設許可權為私有

struct    預設許可權為公共

示例程式碼:

#include <iostream>
using namespace std;
#include <string>

class Student
{
	string name;
};

struct Teacher
{
	string name;
};

int main() 
{
	Student s1;
	// s1.name = "godv";    報錯訪問不到
	Teacher t1;
	t1.name = "godv";
	return 0;
}

 

相關文章