简体   繁体   中英

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.

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.

I initialize the three in the constructor on lines 25-27 here .

And perform the first operation specifically on previewPath on line 2 here EDIT: only allowed 2 explicit links it seems(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.

Is this an issue with visual studio or with my code? 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);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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