Is legal use initializer_list to initialize an object with derived types?
问题 Well, maybe from the title is not clear what I'm actually asking. I have a class with an initializer-list constructor std::initializer_list<B> . Is legal initialize it with an initializer list of objects of class D , where D is derived from B ? #include <initializer_list> struct B { B(int) {} }; struct D: public B { D(int s): B(s) {} }; struct Foo { Foo(std::initializer_list<B> l) {} }; void main() { Foo f{ D{ 1 }, D{ 2 } }; } If is not legal, is that ill-formed? or just undefined behavior? I