Home > Back-end >  Why can't a pointer to the parent class access subclasses or member of itself???????
Why can't a pointer to the parent class access subclasses or member of itself???????

Time:11-02

The parent class in the worker. In h
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 subclass

CodePudding user response:

refer to the second floor truth is right or wrong response:
you have two zhize_num, remove the subclasses of

Thank you, god wants us to meet a few wrong people wake up a language point
  • Related