samedi 25 septembre 2021

C++: Question on the usage of = on the assignment to a constexpr constructor

I have the below code:

class Debug {
public:
  constexpr Debug(bool b = true) : hw(b), io(b) {} 
  constexpr bool isDebug() const { return this-> debug; }  
  bool getHw() {
     return this-> hw;
  }
  bool getIo() {
     return this-> io;
  }

private:
  bool hw;
  bool io;
};

int main() {
  constexpr Debug dbg = false;
  cout << dbg.getHw() << endl;
  cout << dbg.getIo() << endl;
}

Results:
1
<null>

I noticed that the "false" is only assiged to the hw. Why io value is null? How do you intepret the assignment statement there? Is it always assign to the first data member?

Thx

Aucun commentaire:

Enregistrer un commentaire