なぜこれが機能しないのですか?
#include <vector>
struct A {
template <typename T> void f(const std::vector<T> &) {}
};
int main() {
A a;
a.f({ 1, 2, 3 });
}
リストの初期化で を初期化できます。ただし、引数リストでa を使用してテンプレート引数を推測するstd::vector<T>
ことはできず、関数に a ではないものを渡します。たとえば、これは機能します:T
std::vector<T>
std::vector<T>
#include <vector>
template <typename T>
struct A {
void f(const std::vector<T> &) {}
};
int main() {
A<int> a;
a.f({ 1, 2, 3 });
}