Skip to content

Commit

Permalink
Merge pull request Light-City#19 from Aurelius84/master
Browse files Browse the repository at this point in the history
Polish cout string and fix comment error
  • Loading branch information
Light-City committed May 31, 2020
2 parents 31c36fb + d391210 commit 1d3f1aa
Showing 1 changed file with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

0 comments on commit 1d3f1aa

Please sign in to comment.