← Back to Question List
C++ Quiz #120
Trailing Return Type With decltype
The return type is written after the arrow: -> decltype(a + b). What does that part do?
📄 Code
1#include <iostream>23template <typename T, typename U>4auto add(T a, U b) -> decltype(a + b) {5 return a + b;6}78int main() {9 std::cout << add(2, 2.5) << "\n";10 std::cout << add(3, 4) << "\n";11 return 0;12}