← Encapsulation, const Correctness & static Members

Instance Counter

hard

Make Widget’s constructor increment count every time a Widget is built. main creates n of them, one per loop iteration, each one going out of scope (and being destroyed) at the end of that same iteration – and yet count should still end up equal to n.

That’s the entire point of static: count is one shared value, not something that resets or gets destroyed along with each individual Widget. Every Widget – however briefly it lives – increments the exact same counter that every other Widget does, which is why the total comes out right even though no single object stays alive to remember it.

Your solution

"Run" uses the sample stdin ("3"). "Submit" checks your code against all 3 test cases.

Test results

Submit your solution to run it against all test cases.

Hints

    Reference solution