mercredi 26 décembre 2018

Class with separated header: can see only initialization value of member variable

I have a Test class defined in its own header, test.h, that is included on main.cpp file. Basically this is the situation:

test.h

class Test
{
    ...
    ...
    ...

public:
    long foo;
};

test.cpp

// Constructor
Test::Test()
{
    foo = 0
}

void Test::someMethod()
{
    // Here foo variable is changed
}

main.cpp

#include "test.h"

using namespace std;

int main()
{
    Test testObject;
    ...
    // Do something with testObject
    ...

    return 0;
}

During debug on Visual Studio 2017 if I stop the execution inside main's code I can't see tha actual value of foo, I see its initialization value:

testObject.foo --> 0

Why this happens? If I stop the execution inside class I see its actual value. This is not happen if I don't separate class implementation on .h and .cpp

Aucun commentaire:

Enregistrer un commentaire