The class worker
{
Public:
Virtual void showworker ()=0;
Virtual string getzhize ()=0;
String m_name;
Int worker_bianhao;
Int zhize_num;
};
In the subclass on the boss. H
The class boss: public worker
{
Public:
Boss (int workerbianhao, string name, int zhizenum)
{
This - & gt; Worker_bianhao=workerbianhao;
This - & gt; M_name=name;
This - & gt; Zhize_num=zhizenum;
}
Void showworker ();
String getzhize ();
String m_name;
Int worker_bianhao;
Int zhize_num;
};
The main part of the code in the source file:
The worker * p=NULL;
The switch (b)
{
Case 1:
{
P=new boss (a, name, b);
Cout & lt; break;
}
CodePudding user response:
The p is the parent class zhize_num, your work is not initialized zhize_num value so far, of course,Is the right thing to boss the constructor calls the superclass constructor initializes its members,
CodePudding user response:
You have two zhize_num, remove the subclassCodePudding user response: