Why doesn't this work?
#include <vector>
struct A {
template <typename T> void f(const std::vector<T> &) {}
};
int main() {
A a;
a.f({ 1, 2, 3 });
}
You can initialize a std::vector<T>
with list initialization. However, you cannot deduce the template argument T
using a std::vector<T>
in the argument list and passing the function something which isn't a 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;
a.f({ 1, 2, 3 });
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With