PDA

View Full Version : Classes Problem


TheLionKing
09-17-2003, 12:08 PM
Hi,

I am creating a game in DirectX. I have tried to implement everything through classes. Here is how it goes:

class cApplication
{
...
...
...
private:
* * cDirectX DirectX;
* * cGame * *Game;
};


class cDirectX
{
...
...
...
private:
* * cDirect3D Direct3D;
};


class cDirect3D
{
...
...
...
private:
* * IDirect3DDevice9 *Device;
};

The problem is ... I want to use Device in cGame class. Device is setup in cDirect3D class.

An easy way is to create an external variable ... but that is not a classes approach :unsure: .

Is there anyway to access Device through cGame. I think its by pointers ... but how :confused: ... any guidelines :blush: ?

baldurk
09-17-2003, 12:20 PM
Either pass the device via a function call or redesign the classes so that either the game class owns the device, or doesn't need to.

Dia Kharrat
09-17-2003, 03:25 PM
You could do this:


class cApplication
{
...
...
...
private:
* *static cDirectX DirectX;
* *cGame * *Game;
public:
* *static cDirectX* getDirectX() * { return &DirectX; }
};


class cDirectX
{
...
...
...
private:
* *cDirect3D Direct3D;
public:
* *cDirect3D* getDirect3D() * { return &Direct3D; }
};


class cDirect3D
{
...
...
...
private:
* *IDirect3DDevice9 *Device;
public:
* *IDirect3DDevice9* getDevice() *{ return Device; }
};


and then in your cGame class, you would do:


* *cApplication::getDirectX()->getDirect3D()->getDevice();

TheLionKing
09-17-2003, 07:25 PM
:yes: Thanks. I think I got the picture ... I will try it tonight ... :) !

TheLionKing
09-18-2003, 11:51 AM
:yes: Thanks apex ... got it working now!