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

前端 未结 11 1097
小蘑菇
小蘑菇 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:57

    Not only you can't, you should not try doing this by messing with const_cast. Static const members have a very high chance of ending up in read-only segment, and any attempt to modify them will cause program to crash.

提交回复
热议问题