如何使用gdb确定基类指针所指的是哪一个子类对象。
https://blog.csdn.net/ddazz0621/article/details/95588244
https://www.codenong.com/8528979/
#include <cstdio>
#include <iostream>
using namespace std;
class A{
public:
virtual bool isUse()
{
cout << "A isUse" << endl;
return true;
}
virtual ~A()
{
cout << "~A" << endl;
}
};
class B:public A
{
public:
bool isUse()
{
cout << "B isUser" << endl;
return false;
}
};
class C:public A
{
public:
bool isUse()
{
cout << "C isUser" << endl;
return false;
}
};
int main()
{
cout << "New B()" << endl;
A* ptr = new B();
cout << "End New B()" << endl;
ptr->isUse();
return 1;
}
在GDB中开启对象类型打印权限:
set print object on
然后使用ptype指令获取但却基类指针所执行的具体对象
ptype ptr
(gdb) ptype ptr
type = /* real type = B * */
class A {
public:
virtual bool isUse(void);
~A();
} *
版权声明:本文为weixin_39828926原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。