class A
{
public:
virtual void print()
{ cout << "A::print()" <<endl;}
};
class B: public A
{
public:
virtual void print()
{ cout << "B::print()" <<endl;}
};
class C: public A
{
public:
virtual void print()
{ cout << "C::print()" <<endl;}
};
void print(A a) // 值传递 实质是复制
{
a.print();
}
void printA(A &a) // 引用传递 是传别名
{
a.print();
}
void main()
{
A a,*aa,*ab,*ac;
B b;
C c;
aa=&a;
ab=&b;
ac=&c;
a.print();
b.print();
c.print();
aa->print();
ab->print();
ac->print();
print(a); //此处注意
print(b);
print(c);
printA(a); //此处注意
printA(b);
printA(c);
}
A::print()
B::print()
C::print()
A::print()
B::print()
C::print()
A::print() //此处注意
A::print()
A::print()
A::print() //此处注意
B::print()
C::print()