列出派生类中的所有方法/变量
List all methods / variables in a derived class
我正在一个遗留项目中工作,偶然发现了一个修改用例。我的分析总结到一堂课。我能够跟踪该类的一些方法,但随着我的继续,它在分析中变得有点乏味。
是否有一种机制/方法可以让我知道给定类的所有方法(用户定义/继承等)及其成员变量,尤其是对于 Linux 平台?
您可以使用 gdb,但这意味着您必须导航到代码的该部分。如果我有一个小程序:
struct AAA {
int iii;
int aonly;
void foo () {
}
};
struct BBB: public AAA {
int iii;
int bonly;
void fooB () {
}
};
int main (int argc, const char* argv[]) {
BBB b;
b.iii = 1;
return 0;
}
我可以使用调试符号(g++ 中的 -g)进行编译,设置断点并打印对象:
eric@mouni2:/tmp/ttt$ g++ -g a.cpp
eric@mouni2:/tmp/ttt$ gdb a.out
*** output flushed ***
(gdb) b 18
Breakpoint 1 at 0x4004e8: file a.cpp, line 18.
(gdb) R
Starting program: /tmp/ttt/a.out
Breakpoint 1, main (argc=1, argv=0x7fffffffe278) at a.cpp:18
18 return 0;
(gdb) ptype b
type = struct BBB : public AAA {
int iii;
int bonly;
public:
void fooB(void);
}
(gdb) p b
$1 = {<AAA> = {iii = -7568, aonly = 32767}, iii = 1, bonly = 0}
(gdb) p b.iii
$2 = 1
(gdb) p b.AAA::iii
$3 = -7568
在那里你可以看到BBB从AAA继承了什么。这不是很好,但总比没有好。
相关文章:
- 如何检测类是否有成员变量?
- C++ 互斥锁可以交叉方法/变量吗?如果是这样,为什么在这里不起作用?
- 类方法变量,如果将它们存储在类本身中会更快吗?
- 将局部方法变量分配给类指针
- 我的类中有方法的指针数组,但我不能调用我的方法.代码如下
- 列出派生类中的所有方法/变量
- 等待中有条件变量的班级破坏
- 相互冲突名称的成员变量和方法变量
- 在C++中对标志使用有符号变量与无符号变量
- 如何处理一个子类有方法,而另一个没有方法的子类?
- C++如果我有一个对象指针,是在堆栈或堆上分配的方法变量
- 有方法的类,我不明白类的外观
- 如何从另一个类访问一个类的方法/变量,而不在c++中实例化它或子类
- 是否有方法为模板参数指定所需的定义
- CMake add_library( 对象 ) 是否有环境变量<lib><src>?
- 为什么当有私有变量时,我需要使引用保持不变
- 为什么C++中有全局变量
- 是否有方法将相对库路径添加到可执行文件以避免设置LD_library_path
- 指定类变量与方法变量C++
- 在c++中是否有方法对成员变量(类)进行后期初始化?