实例化worker对象时,无法访问private成员是什么鬼 我都定义为public型的数据成员了
Person类
#ifndef PERSON_H
#define PERSON_H
#include<iostream>
using namespace std;
class Person
{
public:
Person(string name)
{
m_strName = name;
cout << "Person()" << endl;
}
virtual ~Person()
{
cout << "~Person()" << endl;
}
virtual void work() = 0;
public:
string m_strName;
};
#endif
Worker类:
#ifndef WORKER_H
#define WORKER_H
#include"Person.h"
class Worker : public Person
{
Worker(string name,int age):Person(name)
{
//m_strName = name;
m_iAge = age;
cout << "Worker()" << endl;
}
virtual void work()
{
cout <<"work()" << endl;
}
public:
int m_iAge;
};
#endif
主函数:
#include<iostream>
//#include"Person.h"
#include"Worker.h"
using namespace std;
int main(void)
{
Worker Workr("lily",67);
system("pause");
return 0 ;
}