I happen to come across this, and I don't get it, why Foo c{a}
called the 2 constructors. I know that every time an object is created, the constructor, is called, so why does it called the foo(std::initializer_list<Foo>)
even if he did not do this Foo c{{a}}
or Foo c({a})
?
struct Foo { Foo() {} Foo(std::initializer_list<Foo>) { std::cout << "initializer list" << std::endl; } Foo(const Foo&) { std::cout << "copy ctor" << std::endl; } }; int main() { Foo a; Foo b(a); // copy ctor Foo c{a}; // copy ctor (init. list element) + initializer list!!! }