Avoid default constructor for member variable

前端 未结 2 850
终归单人心
终归单人心 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:27

    Use MIL - Member Initialization List MIL

    0 讨论(0)
  • 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)
    {}
    
    0 讨论(0)
提交回复
热议问题