带分隔标头的类:只能看到成员变量的初始化值
Class with separated header: can see only initialization value of member variable
我在自己的标头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 变量
相关文章:
- 将成员变量添加到共享库中的类中,不会破坏二进制兼容性吗
- 具有奇怪重复模板模式的派生类中的成员变量已损坏
- 内置函数可查看CPP中的成员变量
- 是否可以初始化不可复制类型的成员变量(或基类)
- 将包含C样式数组的对象初始化为成员变量(C++)
- 为什么我不能在一个类的不同行中声明和定义成员变量?
- 在循环中按顺序遍历成员变量
- c++类声明时,相同的例程,不同的成员变量类型
- 如何从另一个文件继承私有成员变量和公共函数
- 在C++类中,是否必须初始化作为数组的成员变量
- 如何从子成员函数修改父公共成员变量
- 我可以在 C++ 中将数据成员/变量从其定义之外添加到结构中吗?
- 从私有成员变量的成员方法返回unique_ptr
- 在派生类中使用基类的私有成员变量的最佳方法
- 静态 constexpr 类成员变量对多线程读取是否安全?
- C++:是否可以使用非静态成员变量模板?
- 打印所有继承的类成员变量和方法
- 如何在复杂继承中访问静态成员变量
- 为什么我不能在返回 const 的布尔函数中为类成员变量赋值?C++
- 成员变量与函数概念检查