99. Constructors-I

Question.2

Two developers initialize a const member:

Developer A -- body assignment:

class Sensor {
   const int id;
public:
   Sensor(int i) { id = i; }  // Assign in body
};

Developer B -- initializer list:

class Sensor {
   const int id;
public:
   Sensor(int i) : id(i) {}  // Init list
};

Which compiles?

Need Help? Refer to the Quick Guide below

Select Answer