c++ 犯的错误

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/Uitachi1/article/details/70666673
一、
#include<string>
using namespace std;           //别忘了加
class person
{
public:
	person();
	~person();
	void eat();
	string m_strName;
	int m_strAge;
};

二、

如果在类中开始不声明为public类型的话,系统默认为private类型,后期用堆初始化将报错

系统报错:error C2248:  worker::worker”: 无法访问 private 成员(在“worker”类中声明)

如:

#include"person.h"
class worker:public person
{
//public:                      //别忘了写public
	worker();
	~worker();
	void work();
	int m_iSalary;
};


猜你喜欢

转载自blog.csdn.net/Uitachi1/article/details/70666673