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

One Counter per Specialization

hardTemplates

Each Counter<T> has a static member made that its constructor increments. Three objects are created. What is printed?

📄 Code

1#include <iostream>
2 
3template <typename T>
4class Counter {
5public:
6 static int made;
7 Counter() { made++; }
8};
9 
10template <typename T>
11int Counter<T>::made = 0;
12 
13int main() {
14 Counter<int> a;
15 Counter<double> b;
16 Counter<int> c;
17 std::cout << Counter<int>::made << " " << Counter<double>::made << "\n";
18 return 0;
19}