100. Constructors-II

Question.4

A developer initializes a struct-like class:

struct SensorConfig {
   uint16_t rate;
   uint8_t bits;
   uint8_t channel;
};

SensorConfig cfg = {1000, 12, 3};
The developer adds a constructor:
struct SensorConfig {
   uint16_t rate;
   uint8_t bits;
   uint8_t channel;
   SensorConfig(uint16_t r) : rate(r), bits(10), channel(0) {}
};

SensorConfig cfg = {1000, 12, 3};  // Still works?

Does the brace-initialization still compile after adding the constructor?

Need Help? Refer to the Quick Guide below

Select Answer