mercredi 15 septembre 2021

Class reference member - Not an error in a class with synthesized constructor but error in user defined constructor

Below errors out. Understood.

class a {
   int b;
   int &c; // uninitialized
   a(int x): b(x) {}
};

Below uses synthesized constructor. Why no error below? How does the synthesized constructor initialize the reference or will it even do that? Reference has to be user initialized from what I understand.

class a {
   int b;
   int &c;
};

Aucun commentaire:

Enregistrer un commentaire