forked from arkingc/note
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
158 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
> 记录gdb调试打印一个类对象的内存分布的方法,方便回顾 | ||
<div align="center"> <img src="../pic/g++-version.png"/> </div> | ||
|
||
代码如下: | ||
|
||
```c++ | ||
#include <iostream> | ||
|
||
using namespace std; | ||
|
||
class Base{ | ||
public: | ||
virtual void f() {cout << "Base::f" << endl;} | ||
virtual void g() {cout << "Base::g" << endl;} | ||
virtual void h() {cout << "Base::h" << endl;} | ||
}; | ||
|
||
class Derived : public Base{ | ||
public: | ||
void print() {cout << "Derived::print" << endl;} | ||
}; | ||
|
||
int main() | ||
{ | ||
cout << sizeof(Derived) << endl; | ||
Derived d; | ||
cout << sizeof(d) << endl; | ||
|
||
return 0; | ||
} | ||
``` | ||
|
||
[gdb的使用]() | ||
|
||
对象的内存模型,虚函数表,已经虚函数指针信息: | ||
|
||
<div align="center"> <img src="../pic/c++-mode-exp-1.png"/> </div> | ||
|
||
<div align="center"> <img src="../pic/c++-mode-exp-1.png"/> </div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.