简体   繁体   English

C++类成员变量初始化一次

[英]C++ class member variable initialize once

I am looking for a way to make sure a c++ class member variable can be initialized only from inside the constructor.我正在寻找一种方法来确保只能从构造函数内部初始化 c++ 类成员变量。 It should not be set or overwritten by memory overflow.它不应被内存溢出设置或覆盖。 What can you suggest me for that?你能给我什么建议?

If you make the member const , it can be initialized in a constructor member initializer but it cannot be assigned.如果您使成员const ,则可以在构造函数成员初始化程序中对其进行初始化,但不能对其进行分配。 That may not protect it from memory overruns, however.但是,这可能无法保护它免受内存溢出的影响。 I'm not sure anything would.我不确定会有什么。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM