← Back to Question List
C++ Code Walkthrough #87
Follow an Explicit Template Type
📄 Code
Read carefully — what does this print?1#include <iostream>23template <typename T>4T add(T first, T second) {5 std::cout << "adding " << first << " and " << second << "\n";6 return first + second;7}89int main() {10 std::cout << add<int>(2.8, 3.9) << "\n";11 std::cout << add<double>(2, 3) << "\n";12 std::cout << add<double>(1.5, 2) << "\n";13 std::cout << add<int>(7, 2.5) << "\n";14 return 0;15}