64,648
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
#include <string>
using namespace std;
class father
{
public:
father(string sName):name(sName){}
virtual void display()
{
cout<<"this is father class";
}
void print()
{
cout<<name;
}
private:
string name;
};
class son: public father
{
public:
son(string ssName):father(ssName){}
void display()
{
cout<<"this is son class";
}
};
void printAndDisplay(const father& x)
{
x.display();
}
int main()
{
son s1("jack");
printAndDisplay(s1);
}