Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > General Computer Discussion > General Computer Support > Please explain this virtual functions matter (c++)

Reply
Thread Tools

Please explain this virtual functions matter (c++)

 
 
smokey1401 smokey1401 is offline
Junior Member
Join Date: Jul 2008
Posts: 1
 
      07-11-2008
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
private virtual functions and pure virtual functions with bodies John Goche C++ 10 12-08-2006 04:00 PM
Virtual functions --- Explain me. ajay.somni@gmail.com C++ 9 05-18-2005 04:40 PM
please help me in distinguish redefining functions, overloading functions and overriding functions. Xiangliang Meng C++ 1 06-21-2004 03:11 AM
Whattsa Matter, Dark Matter?? A.Melon DVD Video 0 05-16-2004 07:05 AM
Virtual functions and virtual base classes - I'm confused Michael Winter C++ 9 09-23-2003 11:17 PM



Advertisments