【问题标题】:Can you use sequential #if blocks in an autoexp.dat preview?您可以在 autoexp.dat 预览中使用顺序 #if 块吗?
【发布时间】:2011-06-19 21:32:10
【问题描述】:

我有一个二次方程结构,我想让它在 Visual Studio 2008 调试器中看起来更好。这是结构:

struct QuadraticEquation
{
    float squareCoefficent; float linearCoefficent; float yIntersection; 
}

我希望它在调试器中显示为格式正确的公式:

3.0x^2 - 1.3x + 6.5

这是 autoexp.dat 预览脚本:

QuadraticEquation{
    preview
    (
        #if($c.squareCoefficent != 0.0f)
        (
            #($c.squareCoefficent, "x^2")
        )
        #if($c.linearCoefficent < 0.0f)
        (
            #(" - ", -$c.linearCoefficent, "x")            
        )
        #elif($c.linearCoefficent > 0.0f)
        (
            #(" + ", $c.linearCoefficent, "x")            
        )
        #if($c.yIntersection < 0.0f)
        (
            #(" - ", -$c.yIntersection)            
        )
        #elif($c.yIntersection > 0.0f)
        (
            #(" + ", $c.yIntersection)            
        )
    )
}

非常直接。但是当我运行代码时,我收到以下错误消息:

ERROR! Autoexp.dat:line(286) for 'QuadraticEquation': Failed to match ')' for preview/children rule

行号对应于第二个#if 分支,从#if($c.linearCoefficent &lt; 0.0f)... 开始

如果我删除除平方系数分支之外的所有内容,它不会出错。如果这意味着我不能有顺序的#if 块,我还能怎么做我想做的事——而不放入 dll 中?

【问题讨论】:

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


    【解决方案1】:

    我认为您必须使用嵌套的#if 来实现这样的目标。检查std::complex&lt;*&gt; 在默认autoexp.dat 中是如何完成的。

    这需要大量输入才能涵盖所有可能的组合。你真的需要那个吗?也许将其简单地显示为结构就足够实用了。

    【讨论】:

    • 是的,我不是手动做所有这些 +/- 组合 - 他们可以跳。感谢您指出std::complex&lt;*&gt;
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-12-26
    • 1970-01-01
    • 1970-01-01
    • 2013-02-11
    • 1970-01-01
    • 1970-01-01
    • 2018-12-17
    相关资源
    最近更新 更多