class GuiBase
{
public:
LPDIRECT3DDEVICE9 p_d3dDevice; //Our rendering device
GuiBase();
virtual ~GuiBase();
virtual void BaseGetD3DDevice(LPDIRECT3DDEVICE9 mp_d3dDevice);
}; typedef GuiBase* LPGUIBASE;
class dxShape : public GuiBase //backgrounds, ornamentals etc
{
public:
dxShape();
virtual ~dxShape();
//
void BaseGetD3DDevice(LPDIRECT3DDEVICE9 mp_d3dDevice);
}; typedef dxShape* LPShape;
initialising base class variables that might change (solved)
Hi, I realise there was a disscussion on something similer in the beginners forum recently, but that was mostly about whether an item should be public or private. What I am trying to figure out is, how can you actually initialise or change a variable in a base class from a derived class?
I know you can use the baseclass constructor in the derived classes constructor, but this doesn't deal with when you want to change something later. I don't think proper virtual functions are what I'm looking for either, because with them you have to change some of the implementation, or parameters etc.
Any way this is what I need help on, basicly how can I set LPDIRECT3DDEVICE9 p_d3dDevice, with dxShape, and not using an initialiser list etc, or changing the function parameters.
ps, I know some of them are public, but I always do that until I am happy with it, then I make them private/protectred etc.
Thanks for your help.
[Edited by - Stevieboy on March 9, 2005 2:03:45 PM]
'protected' is the middle ground you're looking for. Derived classes [that are declared public or protected] have access to the base class' protected members, but not the private ones.
CM
CM
Hi, yeah I know but thats not my problem what I was trying to do is set the bases LPDIRECT3DDEVICE9 p_d3dDevice, member from dxShape? Do I actually need a separate LPDIRECT3DDEVICE9 member for dxShape? When ever I try to run this at the moment my program crashes.
This (modified) part of the code should work fine:
You don't need a seperate version for your derived class at all.
class dxShape : public GuiBase //backgrounds, ornamentals etc{public: dxShape() {p_d3dDevice = /*Blah*/;}
You don't need a seperate version for your derived class at all.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement