實例化worker對象時,無法訪問private成員是什么鬼 我都定義為public型的數(shù)據(jù)成員了
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
主函數(shù):
#include<iostream>
//#include"Person.h"
#include"Worker.h"
using namespace std;
int main(void)
{
Worker Workr("lily",67);
system("pause");
return 0 ;
}
2016-11-30
Worker的構(gòu)造函數(shù)寫在private里了
2016-11-30
沒寫訪問限定就默認(rèn)是private
2016-11-30
是 worker 類中? 構(gòu)造函數(shù) 沒有定義成 public ????赫赫,,
2016-11-30
呃呃呃 說錯餓了
2016-11-30
eee??? Worker 類?? 中有?純 虛函數(shù)? 這時?? worker 是抽象類???? 不能?? 實例化