为什么我的C ++对象丢失了VPTr [英] Why does my C++ object loses its VPTr

查看:113
本文介绍了为什么我的C ++对象丢失了VPTr的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在调试程序的核心转储之一时,我遇到了一个场景,即它包含的多态对象丢失了VPTr,并且可以看到它指向NULL.

While debugging one of the program's core dump I came across the scenario where its contained object which is polymorphic loses its VPTr and I can see its pointing to NULL.

当对象丢失其VPTr时会发生什么情况.

What could be the scenario when an object loses its VPTr.

预先感谢, Brijesh

Thanks in advance, Brijesh

推荐答案

  1. 内存已被清除,即某些东西覆盖了内存.

  1. The memory has been trashed, i.e. something overwrote the memory.

您通过调用delete或直接调用析构函数销毁了它.通常,这不会使vptr变为NULL,最终只会使其指向基类的vtable,但这取决于您的实现.

You destroyed it by calling delete or by invoking the destructor directly. This typically does not NULL out the vptr, it will just end up having it point to the vtable of the base class, but that depends on your implementation.

情况1最有可能.如果您的调试器具有内存断点,并且可以可靠地重现该问题,请在vptr上设置一个内存断点,然后查看对其进行了哪些修改.

Most likely, case 1. If you have a debugger that has memory breakpoints and if you can reproduce the problem reliably, set a memory breakpoint on the vptr and see what's modifying it.

这篇关于为什么我的C ++对象丢失了VPTr的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆