jjzjj

c++ - 条件断点 : This expression has side effects and will not be evaluated

coder 2023-11-14 原文

我有一个名为 size_t A::m() const 的非静态常量方法,如果它返回的值大于 1,我想用它来触发断点。这是 A 类 和实例 a:

class A
{
public:
    std::vector<double> myvec;
    size_t m() const
    {
      return myvec.size();
    }
} a;

所以我在 Visual Studio 2013 中添加了一个断点,这个条件

a.m() > 1 // a is an instance of class A

但是,当我尝试编译它时,我从 IDE 收到以下消息:

The following breakpoint cannot be set:

At myFile.cpp, line xxx, when 'a.m() > 1' is true

This expression has side effects and will not be evaluated.

请注意,A::m() 不会修改任何内容,它只会调用 vector 的 .size() 方法并返回该值,因此断言表达式有副作用是完全错误的。事实上,替换断点条件为a.myvec.size() > 1(即方法本身的内容)具有相同的效果!

关于什么可以用作断点中的条件,Microsoft says that ;

The condition can be any valid expression that is recognized by the debugger.

所以我去看了Expressions in the Debugger , 和 found this :

One common cause of side effects is evaluating a function call in a debugger window. Such evaluations are usually noticeable. A more subtle cause of side effects is the evaluation of properties and other implicit function calls in managed code.

The debugger cannot tell whether a property evaluation or implicit function call has side effects. Therefore, by default, the debugger does not evaluate implicit function calls automatically. Property evaluation is allowed by default, but can be turned off in the Options dialog box. When a function call or property has not been evaluated, a refresh icon appears. You can manually evaluate the expression by clicking the refresh icon. For details, see How to: Refresh Watch Values.

When evaluation of properties or implicit function calls is turned off, you can force evaluation by using the ac format modifier (for C# only). See Format Specifiers in C#.

如果有人能将上面的段落翻译成英文那就太好了。我能否将函数放入这些调试器条件语句中?

最佳答案

这是我对您提供的帮助链接的翻译:

  • 第 1 段:调用函数可能有副作用。评估属性可能会产生副作用。
  • 第 2 段:调试器无法判断是否存在副作用,因此我们只是假设:“函数 = 坏”、“属性 = 好”(即“函数有副作用,属性没有” ).刷新与当前问题无关的图标信息。
  • 第 3 段:想要强制调试器?如果您使用的是 C#,请在求值后放置 ,ac

所以,归结起来就是,如果你想在你的评估中调用一个函数并且正在使用 C#,在它后面加上 ,ac

a->m() > 1,ac

由于您使用的是 C++,我认为这可以归结为“您的评估语句中没有函数!”出于调试的目的,您可能可以从 A::m 中删除常量,因为说明符不会(不应该)对逻辑流产生任何影响.不过,我什至不确定这是否可行。

关于c++ - 条件断点 : This expression has side effects and will not be evaluated,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19778948/

有关c++ - 条件断点 : This expression has side effects and will not be evaluated的更多相关文章

  1. ruby-on-rails - 如何优雅地重启 thin + nginx? - 2

    我的瘦服务器配置了nginx,我的ROR应用程序正在它们上运行。在我发布代码更新时运行thinrestart会给我的应用程序带来一些停机时间。我试图弄清楚如何优雅地重启正在运行的Thin实例,但找不到好的解决方案。有没有人能做到这一点? 最佳答案 #Restartjustthethinserverdescribedbythatconfigsudothin-C/etc/thin/mysite.ymlrestartNginx将继续运行并代理请求。如果您将Nginx设置为使用多个上游服务器,例如server{listen80;server

  2. ruby - 如何根据特征实现 FactoryGirl 的条件行为 - 2

    我有一个用户工厂。我希望默认情况下确认用户。但是鉴于unconfirmed特征,我不希望它们被确认。虽然我有一个基于实现细节而不是抽象的工作实现,但我想知道如何正确地做到这一点。factory:userdoafter(:create)do|user,evaluator|#unwantedimplementationdetailshereunlessFactoryGirl.factories[:user].defined_traits.map(&:name).include?(:unconfirmed)user.confirm!endendtrait:unconfirmeddoenden

  3. ruby - 在 Ruby 中有条件地定义函数 - 2

    我有一些代码在几个不同的位置之一运行:作为具有调试输出的命令行工具,作为不接受任何输出的更大程序的一部分,以及在Rails环境中。有时我需要根据代码的位置对代码进行细微的更改,我意识到以下样式似乎可行:print"Testingnestedfunctionsdefined\n"CLI=trueifCLIdeftest_printprint"CommandLineVersion\n"endelsedeftest_printprint"ReleaseVersion\n"endendtest_print()这导致:TestingnestedfunctionsdefinedCommandLin

  4. ruby - 定义方法参数的条件 - 2

    我有一个只接受一个参数的方法:defmy_method(number)end如果使用number调用方法,我该如何引发错误??通常,我如何定义方法参数的条件?比如我想在调用的时候报错:my_method(1) 最佳答案 您可以添加guard在函数的开头,如果参数无效则引发异常。例如:defmy_method(number)failArgumentError,"Inputshouldbegreaterthanorequalto2"ifnumbereputse.messageend#=>Inputshouldbegreaterthano

  5. ruby - 使用 `+=` 和 `send` 方法 - 2

    如何将send与+=一起使用?a=20;a.send"+=",10undefinedmethod`+='for20:Fixnuma=20;a+=10=>30 最佳答案 恐怕你不能。+=不是方法,而是语法糖。参见http://www.ruby-doc.org/docs/ProgrammingRuby/html/tut_expressions.html它说Incommonwithmanyotherlanguages,Rubyhasasyntacticshortcut:a=a+2maybewrittenasa+=2.你能做的最好的事情是:

  6. ruby - 如何计算 Liquid 中的变量 +1 - 2

    我对如何计算通过{%assignvar=0%}赋值的变量加一完全感到困惑。这应该是最简单的任务。到目前为止,这是我尝试过的:{%assignamount=0%}{%forvariantinproduct.variants%}{%assignamount=amount+1%}{%endfor%}Amount:{{amount}}结果总是0。也许我忽略了一些明显的东西。也许有更好的方法。我想要存档的只是获取运行的迭代次数。 最佳答案 因为{{incrementamount}}将输出您的变量值并且不会影响{%assign%}定义的变量,我

  7. ruby-on-rails - 使用包含多个关联和单独的条件 - 2

    我的Gallery模型中有以下查询:media_items.includes(:photo,:video).rank(:position_in_gallery)我的图库模型有_许多媒体项,每个都有一个照片或视频关联。到目前为止,一切正常。它返回所有media_items包括它们的photo或video关联,由media_item的position_in_gallery属性排序。但是我现在需要将此查询返回的照片限制为仅具有is_processing属性的照片,即nil。是否可以进行相同的查询,但条件是返回的照片等同于:.where(photo:'photo.is_processingIS

  8. ruby-on-rails - 在 haml View 中重构条件 - 2

    除了可访问性标准不鼓励使用这一事实指向当前页面的链接,我应该怎么做重构以下View代码?#navigation%ul.tabbed-ifcurrent_page?(new_profile_path)%li{:class=>"current_page_item"}=link_tot("new_profile"),new_profile_path-else%li=link_tot("new_profile"),new_profile_path-ifcurrent_page?(profiles_path)%li{:class=>"current_page_item"}=link_tot("p

  9. ruby-on-rails - 在具有 ActiveRecord 条件的相关模型中按字段排序 - 2

    我正在尝试按Rails相关模型中的字段进行排序。我研究的所有解决方案都没有解决如果相关模型被另一个参数过滤?元素模型classItem相关模型:classPriority我正在使用where子句检索项目:@items=Item.where('company_id=?andapproved=?',@company.id,true).all我需要按相关表格中的“位置”列进行排序。问题在于,在优先级模型中,一个项目可能会被多家公司列出。因此,这些职位取决于他们拥有的company_id。当我显示项目时,它是针对一个公司的,按公司内的职位排序。完成此任务的正确方法是什么?感谢您的帮助。PS-我

  10. arrays - Ruby 数组 += vs 推送 - 2

    我有一个数组数组,想将元素附加到子数组。+=做我想做的,但我想了解为什么push不做。我期望的行为(并与+=一起工作):b=Array.new(3,[])b[0]+=["apple"]b[1]+=["orange"]b[2]+=["frog"]b=>[["苹果"],["橙子"],["Frog"]]通过推送,我将推送的元素附加到每个子数组(为什么?):a=Array.new(3,[])a[0].push("apple")a[1].push("orange")a[2].push("frog")a=>[[“苹果”、“橙子”、“Frog”]、[“苹果”、“橙子”、“Frog”]、[“苹果”、“

随机推荐