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

Pair<int, double> Versus Pair<double, int>

easyTemplates

Both objects are made from the same class template. Which statement about a and b is true?

📄 Code

1#include <iostream>
2 
3template <typename K, typename V>
4class Pair {
5 K first;
6 V second;
7public:
8 Pair(K f, V s) : first(f), second(s) {}
9 void print() const { std::cout << first << " " << second << "\n"; }
10};
11 
12int main() {
13 Pair<int, double> a(1, 2.5);
14 Pair<double, int> b(2.5, 1);
15 a.print();
16 b.print();
17 return 0;
18}