Avoid default constructor for member variable

前端 未结 2 849
终归单人心
终归单人心 2021-01-27 16:14

I have a class with a member variable of another class:

class MeasurementUnit {
private:
    MeasurementMultiplier _multiplier;

Actually I woul

2条回答
  •  时光说笑
    2021-01-27 16:30

    In all constructors of your class MeasurementUnit, you need to initialize the member variable _multiplier in the initializer list. Example:

    MeasurementUnit::MeasurementUnit()
      : _multiplier(1,2,3)
    {}
    

提交回复
热议问题