Can I initialize a static const member at run-time in C++?

前端 未结 11 1070
小蘑菇
小蘑菇 2020-12-09 16:22

Is it possible to initialize a static const member of my class during run-time? This variable is a constant throughout my program but I want to send it as a command-line arg

11条回答
  •  执念已碎
    2020-12-09 16:47

    No, since you defined the variable as static and const, you cannot change its value. You will have to set its value in the definition itself, or through a constructor called when you create an object of class A.

提交回复
热议问题