请教下C++对象的虚表在什么情况下可能会被清空

zhousitiaoda 2015-10-21 06:18:10
具体是一个com对象,crash时发现虚表里的内容都被清空了(都是0),vptr倒是不为0,其他成员看上去都是正常的。感到有点匪夷所思,特请教下。。
...全文
199 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
赵4老师 2015-10-22
  • 打赏
  • 举报
回复
To break when the value at a specified memory address changes From the Edit menu, click Breakpoints. Click the Data tab of the Breakpoints dialog box. In the Expression text box, type the memory address for the byte. For a word or doubleword memory address, enclose the address in parentheses, and precede it with a cast operator. For example, WO(21406036) for the word at memory location 21406036. Use the cast operator BY for a byte (optional), WO for a word, or DW for a doubleword. (The debugger interprets all integer constants as decimal unless they begin with zero (0) for octal or zero and x (0x) for hexadecimal.) In the Number Of Elements text box, type the number of bytes, words, or doublewords to monitor. If you used the BY operator in the Expression field, specify the number of bytes. If you used WO, specify the number of words. If you used DW, specify the number of doublewords. Click OK to set the breakpoint.
paschen 版主 2015-10-22
  • 打赏
  • 举报
回复
引用 1 楼 adlay 的回复:
应该是永远都不会的,虚表是编译的时候为每个类生成的静态数据,一直都在的,对象创建的时候只会让 vptr 指向那里。 出现为空,要么是你的 vptr 指针本身被改变了,指向了错误的地方,要么是某些内存访问越界,把对应的内存给覆盖了。
正解 另参看:《深度探索C++对象模型》
zhousitiaoda 2015-10-21
  • 打赏
  • 举报
回复
引用 1 楼 adlay 的回复:
应该是永远都不会的,虚表是编译的时候为每个类生成的静态数据,一直都在的,对象创建的时候只会让 vptr 指向那里。 出现为空,要么是你的 vptr 指针本身被改变了,指向了错误的地方,要么是某些内存访问越界,把对应的内存给覆盖了。
多谢指点,我再review下代码,看有没有这两种可能。。
fefe82 2015-10-21
  • 打赏
  • 举报
回复
你的程序写错了,写到了不该写地方。(这应该也是你的程序 crash 的原因)。 可能某次这个不该写的地方正好是虚表。
www_adintr_com 2015-10-21
  • 打赏
  • 举报
回复
应该是永远都不会的,虚表是编译的时候为每个类生成的静态数据,一直都在的,对象创建的时候只会让 vptr 指向那里。 出现为空,要么是你的 vptr 指针本身被改变了,指向了错误的地方,要么是某些内存访问越界,把对应的内存给覆盖了。

64,678

社区成员

发帖
与我相关
我的任务
社区描述
C++ 语言相关问题讨论,技术干货分享,前沿动态等
c++ 技术论坛(原bbs)
社区管理员
  • C++ 语言社区
  • encoderlee
  • paschen
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
  1. 请不要发布与C++技术无关的贴子
  2. 请不要发布与技术无关的招聘、广告的帖子
  3. 请尽可能的描述清楚你的问题,如果涉及到代码请尽可能的格式化一下

试试用AI创作助手写篇文章吧