mercredi 6 juillet 2022

C++ can I initialize member variable based on a just initialized another member variable? [duplicate]

If I initialize member variable a, can I immediately read the value of a to initialize b?

Is this guaranteed by C++(11) specifications to work always with all compilers?

Is there any side effect?

E.g:

class X {
   public:
   int a;
   int b;  
   X() : a(1), b(a+1) {}
};    

Aucun commentaire:

Enregistrer un commentaire