Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
静态类错误 这是C++。_C++_Oop_Polymorphism - Fatal编程技术网

静态类错误 这是C++。

静态类错误 这是C++。,c++,oop,polymorphism,C++,Oop,Polymorphism,我真的不知道问题出在哪里,因为这两个静态类型都是相同的,但它只正确显示员工信息,当涉及到患者信息时,它只显示输入日期和输出日期,而不显示人员信息,(员工正确打印人员信息) void*打印(){ 节点*aux; aux=此->头部; while(辅助){ Employee*Employee=static_cast(aux->getPerson()); 患者*Patient=static_cast(aux->getPerson()); 如果(雇员){ 员工->信息(); } 否则,如果(患者){ 患

我真的不知道问题出在哪里,因为这两个静态类型都是相同的,但它只正确显示员工信息,当涉及到患者信息时,它只显示输入日期和输出日期,而不显示人员信息,(员工正确打印人员信息)

void*打印(){
节点*aux;
aux=此->头部;
while(辅助){
Employee*Employee=static_cast(aux->getPerson());
患者*Patient=static_cast(aux->getPerson());
如果(雇员){
员工->信息();
}
否则,如果(患者){
患者->信息();
//应该是上述情况之一
}
aux=aux->getNext();
}
返回0;
就在我打印这个的时候,它只打印员工信息,但不显示患者信息

class Patient: public Person {

private:
int Id_Patient;
Person person;
string Date_In;
string Date_Out;

public:
    Patient(){
        this->Date_In;
        this->Date_Out;
    }
    Patient (int Id_Patient, Person person){
        this->Id_Patient=Id_Patient;
        this->person=person;
    }
    Patient (int Id_Patient, Person person, string Date_In, string Date_Out){
        this->Id_Patient=Id_Patient;
        this->Date_Out=Date_Out;
        this->Date_In=Date_In;
    }
    void setId_Patient(int Id_Patient){
        this->Id_Patient=Id_Patient;}
    int getId_Patient(){
        return this->Id_Patient;}

    void setDate_In(string Date_In){
        this->Date_In=Date_In;}
    string getDate_In(){
        return this->Date_In;}

    void setDate_Out(string Date_Out){
        this->Date_Out=Date_Out;}
    string getDate_Out(){
        return this->Date_Out;} 

    void setPerson(Person person) {
        this->person=person;    }       
    Person getPerson() {
        return this->person;}       

    void info() {
        cout <<"=================================" << endl; 
        cout << "Patient ID: " << this->Id_Patient << endl;
        this->person.info();
        cout << "Date_In: " << this->Date_In << endl;
        cout << "Date_Out: "<< this->Date_Out << endl;
        cout <<"=================================" << endl; 
    }               
患者类别:公众人士{
私人:
内部Id_患者;
个人;
字符串日期_In;
串出日期;
公众:
病人(){
此->日期\u In;
这个->日期;
}
患者(内部Id_患者,个人){
此->Id\u患者=Id\u患者;
这个->人=人;
}
患者(int-Id\u-Patient、Person-Person、字符串日期\u-In、字符串日期\u-Out){
此->Id\u患者=Id\u患者;
此->日期=日期;
此->日期\输入=日期\输入;
}
无效设置Id_患者(内部Id_患者){
此->Id\u Patient=Id\u Patient;}
int getId_患者(){
返回此->Id_Patient;}
void setDate_In(字符串日期_In){
此->日期\u In=日期\u In;}
字符串getDate_In(){
返回此->日期_In;}
无效设置日期输出(字符串日期输出){
此->日期=Date\u Out;}
字符串getDate_Out(){
返回此->日期_Out;}
无效设置个人(个人){
此->个人=个人;}
Person getPerson(){
返回此->个人;}
无效信息(){
cout Employee_Code;}
无效固定工资(双倍工资){
此->薪资=薪资;}
双薪{
返回此->薪资;}
无效设置个人(个人){
此->个人=个人;}
Person getPerson(){
返回此->个人;}
无效信息(){

coutOP似乎混淆了。但是有一种更好的方法可以消除任何铸造的需要:将纯虚拟方法
virtualvoid info()=0;
添加到
Person

Patient
Employee
info
将实现
Person
info
打印

aux->getPerson()->info();
都做完了


<> P>话题,返回代码<>空> */> >从<代码>打印< /COD> >代码> VUT> <代码>是一个失败的想象,糟糕的计划,或者C++中与C库的接口。你几乎不应该使用它,当然也不要去代码>返回0 。我需要返回,但我删除了它,它工作得很好。此外,尝试了aux->getPerson()->info();但编译错误,[Error]无法将“aux->Node::getPerson()->Person::info()”(类型为“void”)动态转换为“class Employee*”(源不是指针)[Error]void值没有被忽略,因为它应该是@user4581301不完全确定所有这些注释的意思,@EduardoGonzalez。我认为它的意思是你
Employee*Employee=dynamic_cast(aux->getPerson()->info();
,这不是必需的。整个
while
循环变成:
while(aux){aux->getPerson()->info();aux=aux->getNext();}
class Employee: public Person {
private:
    int Employee_Code;
    Person person;
    double Salary;
public:
    Employee() {
        this->Employee_Code;
        this->Salary;}

    Employee(int Employee_Code, Person person){
        this->Employee_Code=Employee_Code;
        this->person=person;
    }
    Employee(int Employee_Code, double Salary){
        this->Employee_Code=Employee_Code;
        this->Salary=Salary;
    }
    Employee(int Employee_Code, Person person, double Salary){
        this->Employee_Code=Employee_Code;
        this->person=person;
        this->Salary=Salary;
    }   
    void setEmployee_Code(int Employee_Code){
        this->Employee_Code=Employee_Code;}
    int getEmployee_Code(){
        return this->Employee_Code;}

    void setSalary(double Salary){
        this->Salary=Salary;}
    double getSalary(){
        return this->Salary;}

    void setPerson(Person person) {
        this->person=person;    }       
    Person getPerson() {
        return this->person;}   

    void info() {
        cout <<"=================================" << endl; 
        cout << "Employee_Code: " << this->Employee_Code << endl;
        this->person.info();
        cout << "Salary: " << this->Salary << endl;
        cout <<"=================================" << endl; 
    }
aux->getPerson()->info();