且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在构造函数中初始化 const 字段?

更新时间:2022-12-14 11:46:14

你需要在初始化列表中进行:

You need to do it in an initializer list:

Bar(Foo* _foo) : foo(_foo) {
}

(请注意,我重命名了传入变量以避免混淆.)

(Note that I renamed the incoming variable to avoid confusion.)