基类引用实现多态
源程序:
#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;
}