← Back to Question List
C++ Quiz #123
A Default Template Argument Fills the Gap
Triple has three type parameters, but the object is created with only two: Triple<int, std::string>. What is C for t, and what is printed?
📄 Code
1#include <iostream>2#include <string>34template <typename A, typename B, typename C = A>5class Triple {6 A first;7 B second;8 C third;9public:10 Triple(A f, B s, C t) : first(f), second(s), third(t) {}11 void print() const {12 std::cout << first << " " << second << " " << third << "\n";13 }14};1516int main() {17 Triple<int, std::string> t(1, "one", 10);18 t.print();19 return 0;20}