#include <atomic>
std::atomic<int> outside(1);
class A{
std::atomic<int> inside(1); // <--- why not allowed ?
};
prog.cpp:4:25: error: expected identifier before numeric constant
prog.cpp:4:25: error: expected ',' or '...' before numeric constant
In VS11
C2059: syntax error : 'constant'
In-class initializers do not support the
(e)syntax of initialization because the committee members that designed it worried about potential ambiguities (For example, the well-knownT t(X());declaration would be ambiguous and does not specify an initialization but declares a function with an unnamed parameter).You can say
Alternatively a default value can be passed in the constructor