基类引用实现多态
源程序:
#include <iostream>
using namespace std;
class A
{
public:
virtual void Print()
{
cout << "A::Print" << endl;
}
};
class B :public A
{
public:
virtual void Print()
{
cout << "B::print" << endl;
}
};
void PrintInfo(A &r)
{
r.Print();
}
int main()
{
A a;
B b;
PrintInfo(a);
PrintInfo(b);
system("pause");
return 0;
}
原文地址:https://www.cnblogs.com/duanqibo/p/12181922.html
时间: 2024-10-21 06:39:13