Why can't I initialize std :: vector using list initialization

Why is this not working?

#include <vector> struct A { template <typename T> void f(const std::vector<T> &) {} }; int main() { A a; af({ 1, 2, 3 }); } 
+6
source share
1 answer

You can initialize std::vector<T> with list initialization. However, you cannot output the template argument T using std::vector<T> in the argument list and pass a function that is not std::vector<T> . For example, this works:

 #include <vector> template <typename T> struct A { void f(const std::vector<T> &) {} }; int main() { A<int> a; af({ 1, 2, 3 }); } 
+13
source

All Articles