← Back to Question List
C++ Quiz #113
Deducing T From a Vector
printFirst receives a whole vector of strings. Which type does the compiler deduce for T, and what is printed?
📄 Code
1#include <iostream>2#include <string>3#include <vector>45template <typename T>6void printFirst(const std::vector<T>& items) {7 std::cout << items[0] << "\n";8}910int main() {11 std::vector<std::string> fruit = {"apple", "pear"};12 printFirst(fruit);13 return 0;14}