我想添加一个静态常量变量到我的类,这是一个结构的实例。由于它是静态的,我必须在类声明中初始化它。尝试这个代码C++初始化静态常量结构变量
class Game {
public:
static const struct timespec UPDATE_TIMEOUT = { 10 , 10 };
...
};
收到此错误:
error: a brace-enclosed initializer is not allowed here before '{' token
error: invalid in-class initialization of static data member of non-integral type 'const timespec'
如何初始化呢?谢谢!
请注意,在C++中几乎不需要详细的类型说明符('struct timespec')。只需编写'timespec'。 – GManNickG