fix comment error and polish cout str

This commit is contained in:
Aurelius84 2020-05-25 09:59:33 +08:00
parent 2f38d6fa15
commit d3912107c4

View File

@ -3,28 +3,28 @@
using namespace std;
class A {
public:
void f(int i){cout<<"A"<<endl;};
void f(int i){cout<<"A::f()"<<endl;};
};
class B: public A {
public:
virtual void f(int i){cout<<"B"<<endl;}
virtual void f(int i){cout<<"B::f()"<<endl;}
};
class C: public B {
public:
void f(int i){cout<<"C"<<endl;}
void f(int i){cout<<"C::f()"<<endl;}
};
//一旦将某个成员函数声明为虚函数后,它在继承体系中就永远为虚函数了
class D: public C{
public:
void f (int){cout<<"D"<<endl;}
void f (int){cout<<"D::f()"<<endl;}
};
int main(){
A *pA,a;
B *pB, b; C c; D d;
pA=&a; pA->f(1); //调用A::f
pB=&b; pB->f(1); //调用A::f
pB=&c; pB->f(1); //调用A::f
pB=&d; pB->f(1); //调用A::f
pB=&b; pB->f(1); //调用B::f
pB=&c; pB->f(1); //调用C::f
pB=&d; pB->f(1); //调用D::f
system("pause");
return 0;
}