Hi, I'm new to this forum. The advice offered looks very sound so I hope I can get the same help...
OK, so I understand the concept of virtual functions: they allow for derived classes to override a base class function and perform different actions that are relevant to the specifically derived class (gasp!). I can write simple programs that demonstrate this concept without [much] problem.
Here is my problem: I have a base class named "TeamMember", and derive two classes from it, "Manager" and "Player". I am trying to override a virtual function named setData(). This function is attempting to allow me to set the attributes of either a manager or player. Now then, both "manager" and "player" have a name, age, and a team. So it would be fair to declare the virtual function with these 3 parameters. HOWEVER, they also have unique attributes, eg a player also has a "position" for example BUT a manager does not. In this case, for example, setData() in the player class now requires 4 parameters. This causes complaints from the compiler. I understand that an overriding function MUST have the same parameters etc, but I thought the idea was to allow the function to have added functionality within a derived class???? Surely on occassions this will require extra parameters to allow for more functionality???? I hope my problem has made sense. If you understand the results I am after, can anyone suggest a more suitable way?
Many thanks in advance,
Alex
|