struct和class区别

struct和class区别

//默认成员权限是private
class Person {
    //private:
	int age;
	void run() {
		cout << "Person::runm()" << endl;
	}
};
//默认成员权限是public
struct Son {
    //public:
	int age;
	void run() {
		cout << "Person::runm()" << age <<endl;
	}
};
int main(){
    //利用类创建对象
    Person person;
    person.age=10;//报错
    Son son;
    son.age=10;//正常
    getchar();
    return 0;
}

总结:默认访问权限不一致,汇编代码都是一致的

posted @ 2020-07-21 17:10  Antake  阅读(106)  评论(0)    收藏  举报
Live2D