CJCoding With Joseph
15free / daySign inCreate account

A static data member in a base class is shared across the whole hierarchy, so it can count every object created, including derived ones.

Create a base class Entity with a public static int count; that is incremented in the Entity constructor. Define the static member outside the class as int Entity::count = 0;.

Create a derived class Player (empty body) whose constructor automatically runs the base constructor and bumps the counter.

After the runner creates one Entity and two Players, it prints Entity::count (see Expected Output).

Do NOT write a main function.

Expected output

3

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

Hints3 available
Topics
Inheritance
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.