class GA
{
public:
virtual int f()
{
return 1;
}
};
class GB :public GA
{
public:
virtual int f()
{
return 2;
}
};
void show(GA g)
{
cout << g.f();
}
void display(GA& g)
{
cout << g.f();
}
void main()
{
GA a;
show(a);
display(a);
GB b;
show(b);
display(b);
}
输出的是1112;
为什么show(b)调用的还是基类的函数 但display(b)调用的却是派生的函数呢?
函数参数中加了一个引用的话有什么不同呢?
麻烦各位看看 谢谢!