Archived

This topic is now archived and is closed to further replies.

Jumpster

Changing member data types

Recommended Posts

Jumpster    122
I want to create a set of classes like shown below:
  
class InputDevice
{
  ....
};

class JOYSTICK : public InputDevice
{
  protected:
    LPINPUTDEVICE2 device;
  ....
};

///////////////////////////////////////////////

///////////////////////////////////////////////

// Force Feed-back supported joystick.

// If Force FeedBack is not supported by the 

// Joystick, default to JOYSTICK class behavior.

// 

class FEEDBACK : public JOYSTICK
{
  protected:
    LPINPUTDEVICE7 device;
  ....
};

  
Currently I have a LPINPUTDEVICE2 device value and added an LPINPUTDEVICE7 feedback value to the FEEDBACK version. Is there a way to do what I illustrated above? Regards, Jumpster Note: I am posting in two-forums because I don''t know if the solution would be DX specific or C++ general.

Share this post


Link to post
Share on other sites
Jumpster    122
Perhaps I am asking the wrong question here?

Let me try again:

I have a base class with a member variable of type "A". I want to inherit from that class, keep the same member variable name but change it to type "B".

Can that be done? If so, how?

Regards,
Jumpster

Share this post


Link to post
Share on other sites
Xai    1838
While I''m not sure that C++ wont let you do it ... try it and see ... i can guarantee you that the effect will not be what you are looking for.

assuming the compiler let you do this ... all you are doing is creating a second variable that hides the first. unlike functions ... there is no virtual variable feature to allow you to do anything usefull with this type of thing. see ... no matter if the variable in the base class is public, private, or protected ... the fact that it is declared there means storage and type are assigned there ...if you additionally define one with the same name in your derived class ...then you have a total of 2 ... and you would only be able to access the base class version like this A::device ... and anything you do to the derived class version B::device has absolutely no effect on the operation of Base class functions (unless they are virtual).

What you are really have to do to get the feature you want is use an abstract base class ... IJoystick ...without the device data member ... then a derived class for the old style joystick ... perhaps Joystick2 ... and another class Joystick7 ... which could either be a sibling of Joystick2, or could be derived from Joystick2 ... therefore not overriding members that do not change ...but the device member in Joystick2 should be PRIVATE if you wish it not to cause bad things when you write Joystick7 ...

Note: The names IJoystick, Joystick, and ForceFeedbackJoystick are better than the ones I used in the example.

Good luck ...feel free to ask for clarification

Share this post


Link to post
Share on other sites