C++20 sections · 1024 units
Open in Course

Team Uniforms - Implementation

Pseudocode solution

Here's the pseudocode with polymorphism: In C++, mark base class methods as virtual for runtime dispatch. You write virtual bool compare(const Team* other) const in the Team class.

Use = 0 for pure virtual methods. This means virtual bool compare(const Team* other) const = 0; in the base Team class.

Store pointers to enable polymorphic behavior. When you have Team* teams[] containing both FootballTeam and BasketballTeam pointers, calling teams[i]->compare(teams[j]) dispatches to the right compare() at runtime .