Jump to content


Classes Problem


4 replies to this topic

#1 TheLionKing

    Valued Member

  • Members
  • PipPipPip
  • 143 posts

Posted 17 September 2003 - 06: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: ?
<span style='color:blue'>I can survive anything ... even NUKES!!!
The Lion King</span>

#2 baldurk

    Senior Member

  • Members
  • PipPipPipPip
  • 1057 posts

Posted 17 September 2003 - 06: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.
baldurk
He who knows not and knows that he knows not is ignorant. Teach him.
He who knows not and knows not that he knows not is a fool. Shun him.

#3 Dia

    DevMaster Staff

  • Administrators
  • 1089 posts

Posted 17 September 2003 - 09: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();


#4 TheLionKing

    Valued Member

  • Members
  • PipPipPip
  • 143 posts

Posted 18 September 2003 - 01:25 AM

:yes: Thanks. I think I got the picture ... I will try it tonight ... :) !
<span style='color:blue'>I can survive anything ... even NUKES!!!
The Lion King</span>

#5 TheLionKing

    Valued Member

  • Members
  • PipPipPip
  • 143 posts

Posted 18 September 2003 - 05:51 PM

:yes: Thanks apex ... got it working now!
<span style='color:blue'>I can survive anything ... even NUKES!!!
The Lion King</span>





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users