vendredi 28 octobre 2016

Is it ever necessary to invoke default ctor in constructor initialization list?

For example, if I have the following:

class Foo;  // has default ctor

class Bar {
 public:
  Bar(Foo* f);
}

class MyClass {
 public:
  MyClass();

 private:
  Foo foo_;
  Bar bar_;
}

MyClass::MyClass() : foo_(), bar_(&foo) {}

This more or less compiles without warnings, see http://ift.tt/2eUOeo1 [slightly modified so Foo is fleshed out].

It also compiles fine without foo_() in the initializer list. But is there ever a case where one would need to invoke the default ctor?

Aucun commentaire:

Enregistrer un commentaire