当指向基类的指针指向特定子类时,有条件地断开的断点

时间:2017-09-12 15:43:55

标签: c++ oop debugging visual-studio-2015 conditional-breakpoint

有没有正确的方法在Visual Studio 2015中设置条件断点,只要指向基类的指针指向指定的子类 类型 ,它就会中断? (见下面的示例截图)

我不想花时间为此编写调试实用程序代码,也不想破解虚拟表数据。

enter image description here

1 个答案:

答案 0 :(得分:1)

两种方法:

在IDE中添加以下作为断点条件:

dynamic_cast<DerivedClassYouWantToBreak*>(ptr.get())

或者在代码中添加以下代码并编译:

if (dynamic_cast<DerivedClassYouWantToBreak*>(ptr.get()))
{
    int breaksHere = 0; // put breakpoint here
}