CJCoding With Joseph
15free / daySign inCreate account

Count Constructions per Template Type

Complete the class template CounterBox<T> so that it counts how many objects of EACH specialization have been constructed:

- a private static int created - the constructor adds 1 to created - static int getCreated() returns it - define the static member outside the class with the template prefix, starting at 0

A static member belongs to the class, and every specialization is its own class, so CounterBox<int> and CounterBox<double> keep separate counts. This is a total-constructions counter: it never goes down when an object is destroyed. The tests build three CounterBox<int> and one CounterBox<double>, print both counts, build another double and print its count, build an int inside a block that ends and print the int count once more, and finally print the total of the three int values; one number per line.

Do NOT write a main function.

Expected Output:

3
1
2
4
6

= newline. The output ends with a newline — print one after the last line.

Hints4 available
Topics:
Templates
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · Ctrl+Space to expand shortcuts (cout, fori)

Your Output

Run your code to see the output here...

Test Cases

Run your code to see test case results.