CJCoding With Joseph
15free / daySign inCreate account
← Back to Question List

Select topics to narrow your question pool, then enable Random to jump to a random question matching your filters.

Topics:
C++ Quiz #113

Deducing T From a Vector

easyTemplates

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>
4 
5template <typename T>
6void printFirst(const std::vector<T>& items) {
7 std::cout << items[0] << "\n";
8}
9 
10int main() {
11 std::vector<std::string> fruit = {"apple", "pear"};
12 printFirst(fruit);
13 return 0;
14}