← Back to Question List
C++ Code Walkthrough #86
Spot the Conflicting Template Arguments
📄 Code
Read carefully — what does this print?1#include <iostream>23template <typename T>4T add(T first, T second) {5 return first + second;6}78int main() {9 std::cout << add(2, 3) << "\n";10 std::cout << add(2.0, 3.0) << "\n";11 // std::cout << add(2, 3.5) << "\n"; // does NOT compile: T would be int from 2 and double from 3.512 std::cout << add<double>(2, 3.5) << "\n";13 std::cout << add<int>(2, 3) << "\n";14 return 0;15}