Skip to content

Commit

Permalink
Merge pull request Light-City#245 from slk000/master
Browse files Browse the repository at this point in the history
doc is not consistent with code in vptr_vtable
  • Loading branch information
Light-City committed Jan 3, 2023
2 parents 2c1b7b0 + f6994de commit f82d3d8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
10 changes: 5 additions & 5 deletions basic_content/vptr_vtable/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,11 @@ int main(void)
Base &p = d; // 基类引用指向派生类实例
cout<<"基类对象直接调用"<<endl;
ptr.fun1();
cout<<"基类对象调用基类实例"<<endl;
cout<<"基类引用指向基类实例"<<endl;
pp.fun1();
cout<<"基类指针指向基类实例并调用虚函数"<<endl;
cout<<"基类指针指向派生类实例并调用虚函数"<<endl;
pt->fun1();
cout<<"基类引用指向基类实例并调用虚函数"<<endl;
cout<<"基类引用指向派生类实例并调用虚函数"<<endl;
p.fun1();

// 手动查找vptr 和 vtable
Expand All @@ -136,11 +136,11 @@ int main(void)
```
基类对象直接调用
Base::fun1()
基类引用指向派生类实例
基类引用指向基类实例
Base::fun1()
基类指针指向派生类实例并调用虚函数
Derived::fun1()
基类引用指向基类实例并调用虚函数
基类引用指向派生类实例并调用虚函数
Derived::fun1()
=======================
vptr_addr:0x401130
Expand Down
2 changes: 1 addition & 1 deletion basic_content/vptr_vtable/vptr1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ int main(void)
pp.fun1();
cout<<"基类指针指向派生类实例并调用虚函数"<<endl;
pt->fun1();
cout<<"基类引用指向基类实例并调用虚函数"<<endl;
cout<<"基类引用指向派生类实例并调用虚函数"<<endl;
p.fun1();


Expand Down

0 comments on commit f82d3d8

Please sign in to comment.