Tag: list-initialization
-
Constructing a vector of structs (with some custom constructors) from exactly two string literals crashes. Why?
18 Can you guess the output of this trivial program? #include <vector> #include <string> #include <exception> #include <iostream> int main() { try { struct X { explicit X(int) {} X(std::string) {} // Just to confuse you more… }; std::vector<X>{"a", "b"}; } catch (std::exception& x) { std::cerr << x.what(); } } Well, I couldn’t, which cost…