为什么非常量静态变量不能在类中初始化? [重复]

问题描述 投票:0回答:0

静态变量不应在类中初始化的推理/逻辑是什么? (为了初始化它,我们也必须将它声明为 const)。如果这是可能的,那会有什么问题?

示例:这是不可能的

struct foo
{
    static int value = 3;
};

但这是:

struct foo
{
    static const int value = 3;
};
c++ constants static-variables in-class-initialization
© www.soinside.com 2019 - 2024. All rights reserved.