Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/154.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++中的父类的继承函数。 这怎么可能 class Patient{ protected: char* name; public: void print() const; } class sickPatient: Patient{ char* diagnose; void print() const; } void Patient:print() const { cout << name; } void sickPatient::print() const { inherited ??? // problem cout << diagnose; } 分类患者{ 受保护的: 字符*名称; 公众: 无效打印()常量; } 病人类别:病人{ 字符*诊断; 无效打印()常量; } 无效患者:打印()常量 { 库特_C++_Oop_Function - Fatal编程技术网

如何从父类调用函数? 我想调用C++中的父类的继承函数。 这怎么可能 class Patient{ protected: char* name; public: void print() const; } class sickPatient: Patient{ char* diagnose; void print() const; } void Patient:print() const { cout << name; } void sickPatient::print() const { inherited ??? // problem cout << diagnose; } 分类患者{ 受保护的: 字符*名称; 公众: 无效打印()常量; } 病人类别:病人{ 字符*诊断; 无效打印()常量; } 无效患者:打印()常量 { 库特

如何从父类调用函数? 我想调用C++中的父类的继承函数。 这怎么可能 class Patient{ protected: char* name; public: void print() const; } class sickPatient: Patient{ char* diagnose; void print() const; } void Patient:print() const { cout << name; } void sickPatient::print() const { inherited ??? // problem cout << diagnose; } 分类患者{ 受保护的: 字符*名称; 公众: 无效打印()常量; } 病人类别:病人{ 字符*诊断; 无效打印()常量; } 无效患者:打印()常量 { 库特,c++,oop,function,C++,Oop,Function,在这种情况下,您可以写: Patient *p = new sickPatient(); p->print(); // sickPatient::print() will be called now. // In your case (without virtual) it would be Patient::print() 还有哪些类别来自患者?如果您的答案与“仅限健康患者”不同,则您的设计是错误的。 class Patient { char* name; virtua

在这种情况下,您可以写:

Patient *p = new sickPatient();
p->print(); // sickPatient::print() will be called now.
// In your case (without virtual) it would be Patient::print()

还有哪些类别来自患者?如果您的答案与
“仅限健康患者”
不同,则您的设计是错误的。
class Patient
{
    char* name;
    virtual void print() const;
}
Patient *p = new sickPatient();
p->print(); // sickPatient::print() will be called now.
// In your case (without virtual) it would be Patient::print()