Skip to content

Commit d391210

Browse files
committed
fix comment error and polish cout str
1 parent 2f38d6f commit d391210

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

practical_exercises/10_day_practice/day6/虚函数/虚函数特性.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,28 @@
33
using namespace std;
44
class A {
55
public:
6-
void f(int i){cout<<"…A"<<endl;};
6+
void f(int i){cout<<"A::f()"<<endl;};
77
};
88
class B: public A {
99
public:
10-
virtual void f(int i){cout<<"…B"<<endl;}
10+
virtual void f(int i){cout<<"B::f()"<<endl;}
1111
};
1212
class C: public B {
1313
public:
14-
void f(int i){cout<<"…C"<<endl;}
14+
void f(int i){cout<<"C::f()"<<endl;}
1515
};
1616
//一旦将某个成员函数声明为虚函数后,它在继承体系中就永远为虚函数了
1717
class D: public C{
1818
public:
19-
void f (int){cout<<"…D"<<endl;}
19+
void f (int){cout<<"D::f()"<<endl;}
2020
};
2121
int main(){
2222
A *pA,a;
2323
B *pB, b; C c; D d;
2424
pA=&a; pA->f(1); //调用A::f
25-
pB=&b; pB->f(1); //调用A::f
26-
pB=&c; pB->f(1); //调用A::f
27-
pB=&d; pB->f(1); //调用A::f
25+
pB=&b; pB->f(1); //调用B::f
26+
pB=&c; pB->f(1); //调用C::f
27+
pB=&d; pB->f(1); //调用D::f
2828
system("pause");
2929
return 0;
3030
}

0 commit comments

Comments
 (0)