Sign in to follow this  

initialising base class variables that might change (solved)

This topic is 4666 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

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;








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]

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
This (modified) part of the code should work fine:

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.

Share this post


Link to post
Share on other sites
oh no, it's my fault...

I didn't use "new" for my dxShape! I was using typedef to make them pointers, but then I forgot to call new.
It works fine now.

thanks anyway.

Share this post


Link to post
Share on other sites

This topic is 4666 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this