jeudi 2 juin 2016

C++11 constructor delegation with aggregate initialization

Is it possible to invoke aggregate initialization within my own definition of the default ctor?

GCC complains "error: constructor delegates to itself" with the below code:

struct X {
  int x, y, z, p, q, r;
  X(): x{}, y{}, z{}, p{}, q{}, r{} { }  // cumbersome
//X(): X{} { }  // the idea is nice but doesn't compile
};

I'm using memset(this, 0, sizeof(*this)) in the ctor body at the moment.

Aucun commentaire:

Enregistrer un commentaire