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
crazy166    122
no, you can''t do it exactly as you stated in the second post.

you could use a template class for your changing type.

in the case of DX stuff, you might be better off to use the QueryInterface support. in that case, any function of FEEDBACK (or any function that operated on FEEDBACK) would take the LPINPUTDEVICE2 device ptr and ask for a LPINPUTDEVICE7 ptr from it.

crazy166
some people think i''m crazy, some people know i am

Share this post


Link to post
Share on other sites
Jumpster    122
Yeah, I knew you could to that but I wanted to keep from having to call the QueryInterface() everytime I wanted to use that variable. Constant calling has to be a bottleneck of sorts.

Ultimately, I have created a new variable:

LPINPUTDEVICE7 feedback_joy;

and call QueryInterface() once and store the result in that value. Then I do this...

if (feedback_joy != NULL)
{
device->Release();
device = NULL;
}

that way, only one value is actually going to be used.

Thanks for your input. I appreciate it.

Regards,
Jumpster

Share this post


Link to post
Share on other sites