Please explain this virtual functions matter (c++)

Discussion in 'General Computer Support' started by smokey1401, Jul 11, 2008.

  1. smokey1401

    smokey1401

    Joined:
    Jul 11, 2008
    Messages:
    1
    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
    smokey1401, Jul 11, 2008
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. lyagushka

    disabled functions in menu

    lyagushka, Feb 22, 2005, in forum: Firefox
    Replies:
    4
    Views:
    773
    lyagushka
    Feb 22, 2005
  2. John Finch
    Replies:
    2
    Views:
    845
    John Finch
    Dec 1, 2003
  3. Chris Tsai
    Replies:
    0
    Views:
    456
    Chris Tsai
    Feb 2, 2005
  4. GS
    Replies:
    9
    Views:
    27,907
    Walter Roberson
    Apr 28, 2005
  5. A.Melon

    Whattsa Matter, Dark Matter??

    A.Melon, May 16, 2004, in forum: DVD Video
    Replies:
    0
    Views:
    599
    A.Melon
    May 16, 2004
Loading...

Share This Page