znevegiveup1
唐僧爱吃唐僧肉
2017-07-17 07:56

求大神指教,菜鸟感激不尽!

  • c++

#include

using namespace std;
class A
{
public:
virtual void fun1()
{
cout<<"Class A1\t";
}
virtual void fun2(float x=0)
{
cout<<"Class A2\n";
}
};
class B:public A
{
public:
virtual void fun1()
{
cout<<"Class B1\t";
}
virtual void fun2(int x=0)
{
cout<<"Class B2\n";
}
};
class C:public B
{
public:
virtual void fun1()
{
cout<<"Class B4:\t";
}
virtual void fun2()
{
cout<<"Class B3\n";
}
};
int main()
{
A *pa;
B *pb;
C c;
pa=&c;
pa->fun1();
pa->fun2();
pb=&c;
pb->fun1();
pb->fun2();
return 0;
}
分析一下该程序的输出

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

1条回答

为你推荐