本文介绍了驱动程序类的C ++ Inharitance问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! Hello Everyone! 请告诉我代码中的问题是什么,因为当我运行这个程序时它只显示基类输出并且没有显示驱动类输出请告诉我是否有人知道这个。Hello Everyone!please tell me what is the problem in the code because when i run this program it only show the Base Class Output and did not show the Drived Class Output please tell me if any one know about this.#include <iostream>using namespace std;class Practice{protected: int ID,Pay; string Name;public: Practice() { cout<<"Now The Object Is Created."<<endl; ID=0; Pay=0; Name=""; } //Here Is Prametrized Constructor Practice(int I,int P,string N) { ID=I; Pay=P; Name=N; } void GetData() { cout<<"Employee Name:"<<Name<<"\n\nEmployee ID:"<<ID<<"\n\nEmployee Pay:" <<Pay<<endl; }};//Now Going To Create Second Class For Inharitanceclass Pay_Roll:public Practice{private: int Salary;public: //Create Constructor For Accessing The Base Class Value Pay_Roll(int i,int d,string n,int S) :Practice(ID,Pay,Name) { Salary=S; } //Now Used Constructor Foe Second Employee Data int Ids() { return ID; } void GetData() {// stringstream SS; cout<<"Employee Name:"<<Name<<"\n\nEmployee ID:" <<ID<<"\n\nEmployee Pay:" <<Pay<<"\n\nEmployee Salary:"<<Salary <<endl; }};int main(){ Practice Obj1(12,35000,"Muhammad Qasim"); Obj1.GetData(); Pay_Roll obj2(13,40000,"Muhammad Usman",50000); obj2.GetData();// cout<<obj2.Ids(); return 0;}推荐答案Pay_Roll(int i,int d,string n,int S):Practice(ID,Pay,Name) PS - 请添加< pre lang =C ++> ...< / pre>我将你的问题修改为你的代码。PS - please add <pre lang="C++"> ... </pre> around your code in the future, as I modified your question to. 这篇关于驱动程序类的C ++ Inharitance问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-13 12:07