[英]Why Volatile Static Member Initialization Generate Redefinition Compilation Error?
My Problem is the following: 我的问题如下:
I have a class with static counter. 我有一个带有静态计数器的类。 I set this counter as volatile because I use this variable in multithreaded environment. 我将此计数器设置为volatile,因为我在多线程环境中使用了此变量。
class.h class.h
class myClass
{
public:
volatile static int mCounter;
(...)
};
class.cpp class.cpp
int myclass::mCounter = 0;
In CPP file, I initialize it, and I obtain the following compilation error: 在CPP文件中,我对其进行了初始化,并获得以下编译错误:
'mCounter' : redefinition; different type modifiers
Why ? 为什么呢
Thanks in Advance. 提前致谢。
您还需要在该行上重复“ volatile”。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.