带分隔标头的类:只能看到成员变量的初始化值

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

本文关键字:成员 变量 初始化 分隔      更新时间:2023-10-16

我在自己的标头test.h中定义了一个测试类,该类包含在main.cpp文件中。基本上是这种情况:

测试.h

class Test
{
    ...
    ...
    ...
public:
    long foo;
};

测试.cpp

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

主.cpp

#include "test.h"
using namespace std;
int main()
{
    Test testObject;
    ...
    // Do something with testObject
    ...
    return 0;
}

在Visual Studio 2017上调试期间,如果我停止在main的代码中执行,我看不到foo的实际值,我看到它的初始化值:

testObject.foo --> 0

为什么会这样?如果我在类中停止执行,我会看到它的实际值。

编辑

我发现了问题。在main()中,我添加了一个单独的线程来启动Test::someMethod()。当我在 main 中停止执行时,我看不到本地线程的 testObject 变量。

有没有办法查看线程的局部变量?

我发现了问题。在main()中,我添加了一个单独的线程来启动Test::someMethod()。当我在 main() 中停止执行时,我看不到本地线程的 testObject 变量