简体   繁体   English

Visual Studio 2010不稳定报告局部变量

[英]Erratic reporting of local variables by Visual Studio 2010

In one of my objects named MoveMethod, I have three TileGridAreas, a data structure I created for storing column-row pairs relative to a specific origin. 在我的一个名为MoveMethod的对象中,我有三个TileGridAreas,这是我创建的一种数据结构,用于存储相对于特定起点的列行对。

The TileGridAreas are fairly basic in their operation, and they function just fine in many other areas of this project, but when I refer to them by pointer within MoveMethod, the changes do not appear correctly, and as such it's gumming up all the pathfinding work I'm trying to accomplish. TileGridAreas在它们的操作中是相当基本的,它们在该项目的许多其他区域中都可以正常工作,但是当我在MoveMethod中通过指针引用它们时,更改不会正确显示,因此,这使所有寻路工作变得困难我正在努力完成。

I initialize the three in the constructor on lines 25-27 here . 我在这里的 25-27行中在构造函数中初始化了三个。

And perform the first operation specifically on previewPath on line 2 here EDIT: only allowed 2 explicit links it seems(http://codepad.org/wXxBL7nb) 并在此处的第2行上专门对PreviewPath执行第一个操作:似乎只允许2个显式链接(http://codepad.org/wXxBL7nb)

It correctly reads that previewPath is empty, and as such performs the addMember function on line 5. I've stepped through it in debug, and there is no reason at all for it not to work, but when it returns from the addMember function to the outer function, a quick look at the locals window shows that it has, for whatever arbitrary reason, decided to add not to previewPath but to possibleDestinations. 它正确地读取了PreviewPath为空,并因此在第5行执行了addMember函数。我已经在调试中逐步执行了它,并且完全没有理由不起作用,而是当它从addMember函数返回到在外部函数中,快速浏览locals窗口显示,无论出于何种原因,它都决定不添加到PreviewPath而是可能的目的地。

Is this an issue with visual studio or with my code? 这是Visual Studio还是我的代码存在问题? I'm finding it ridiculously difficult to debug the functional part of the object when the source I'm relying on for accurate information about the involved variables is flat out wrong. 当我依靠源获取有关所涉及变量的准确信息的绝对错误时,我发现调试对象的功能部分非常困难。

Works fine for me. 对我来说很好。 I cut down the code to the smallest runnable version - you should do this yourself in future. 我将代码缩减为最小的可运行版本-您以后应该自己做。

#include <assert.h>

class TileGridArea
{
public:
    TileGridArea() : changed (false) {}

    void addMember(int,int) {changed = true;}

    bool changed;
};

class MoveMethod
{
public:
    MoveMethod()
    {
        movePath = new TileGridArea();
        previewPath = new TileGridArea();
        possibleDestinations = new TileGridArea();
    }

    TileGridArea* movePath;
    TileGridArea* previewPath;
    TileGridArea* possibleDestinations;
};

int main()
{
    MoveMethod m;

    m.previewPath->addMember(3,4);
    assert(m.previewPath->changed);
    assert(!m.possibleDestinations->changed);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM