// Illustrates ambiguities in certain initializations. #include #include #include int main(){ using std::vector; using std::string; // A trap: vector v1{99}; // A vector with single int element, with value 99 - prefer list initialization vector v2(99); // A vector of 99 ints with default value 0 - forces use of a Vector constructor // As expected: vector v3{"hello"}; // A vector with single string element "hello" vector v4("hello"); // ERROR: There is no vector constructor with a single string parameter for(auto x: v1) std::cout << x << std::endl; // 99 for(auto x: v2) std::cout << x << std::endl; // 0 0 ... 0 (99 zeros) for(auto x: v3) std::cout << x << std::endl; // hello }