Classes Problem

40da7e74fdca33768b6714646853b3f5
0
TheLionKing 101 Sep 17, 2003 at 18:08

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: ?

4 Replies

Please log in or register to post a reply.

0684f9d33f52fa189aad7ac9e8c87510
0
baldurk 101 Sep 17, 2003 at 18:20

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.

Fdbdc4176840d77fe6a8deca457595ab
0
dk 158 Sep 17, 2003 at 21:25

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();
40da7e74fdca33768b6714646853b3f5
0
TheLionKing 101 Sep 18, 2003 at 01:25

:yes: Thanks. I think I got the picture … I will try it tonight … :) !

40da7e74fdca33768b6714646853b3f5
0
TheLionKing 101 Sep 18, 2003 at 17:51

:yes: Thanks apex … got it working now!