Override the Square Shape

Easy

The describe function takes a Shape& and calls the virtual functions name() and sides(), so the right override is chosen at run time through the vtable. Triangle overrides both, but Square does not yet, so it is reported as a generic shape with 0 sides. Complete Square so the output is correct. Then switch the assembly panel to -O0 and look inside describe: find the load of the hidden vtable pointer from the object and the indirect call through a register that together make virtual dispatch work.

Success Criteria

Your code must pass 1 test case(s) to complete this exercise. 3 hint(s) are available if you need help.

Sign in to track your progress

You can work on exercises as a guest, but sign in to track your progress and save your submissions.

This platform is built by its community

Every lesson, project, and tool on HelloC++ is funded by sponsors. Join them and help shape what we build next.

Become a Patron