You need to repeat the "volatile" on that line as well.
Why Volatile Static Member Initialization Generate Redefinition Compilation Error?
-
09-03-2022 - |
Вопрос
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.
class.h
class myClass
{
public:
volatile static int mCounter;
(...)
};
class.cpp
int myclass::mCounter = 0;
In CPP file, I initialize it, and I obtain the following compilation error:
'mCounter' : redefinition; different type modifiers
Why ?
Thanks in Advance.
Решение
Не связан с StackOverflow