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 #123

A Default Template Argument Fills the Gap

mediumTemplates

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>
3 
4template <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};
15 
16int main() {
17 Triple<int, std::string> t(1, "one", 10);
18 t.print();
19 return 0;
20}