【问题标题】:Visual Studio doesn't recognize boolean as variableVisual Studio 无法将布尔值识别为变量
【发布时间】:2017-01-09 17:01:29
【问题描述】:

我想在 test2 为真时中断。它不会让我在 test2 设置为 true 的条件内设置断点。因此,我尝试在声明 test3 的位置下方放置一个条件断点:

        string teststring = "debug";
        bool threedistinct = false;
        bool test2 = false;
        if(teststring.find("d") != string::npos)
            threedistinct = true;
        if(threedistinct)
            test2 = true;

        bool test3 = false;

我收到以下错误:

我不明白 test2 怎么可能是未定义的。我尝试将其类型更改为 int,将其初始化为 1,并在条件中更改其值,但我得到了相同的错误。注意:错误仅在我尝试设置断点时出现。

【问题讨论】:

  • 如果您能包含minimal reproducible example,那就太好了,这样我们也可以尝试并重现您的问题。
  • 添加test2 变量后,您是否保存了文件?因为,从屏幕截图来看,您似乎没有保存它。
  • 按照指示显示您的minimal reproducible example,而不是sn-p。
  • 好的,我会编辑的。
  • 您是在发布模式还是调试模式下编译?根据优化级别,可能会去除 test2。

标签: c++ visual-studio scope visual-studio-debugging


【解决方案1】:

“我不小心在最大责任模式下编译。我改为发布到调试,它可以工作。谢谢!”

很高兴知道您已解决此问题。但我同意 PaulMcKenzie 的建议,真正的问题是两种不同模式下的某些设置无法生成调试信息。

(1将生成调试信息的链接器设置。 (2)禁用优化选项。

关于类似问题的参考:

http://www.databasesql.info/article/896010299/

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-10-03
    • 1970-01-01
    • 1970-01-01
    • 2021-12-12
    • 2021-12-01
    • 1970-01-01
    相关资源
    最近更新 更多