Templates inferring type T from return type
问题 I have a template as follows: template <class T> vector<T> read_vector(int day) { vector<T> the_vector; {...} return the_vector; } I would like to be able to do something like vector<int> ints = read_vector(3); vector<double> doubles = read_vector(4); Is it possible for C++ templates to infer the return type from when they're called, or should I just pass a dummy argument to the template with the type I want to the vector to have? The latter works but is messier. 回答1: #include <vector> struct