Jump to content
  • Advertisement
Sign in to follow this  

Dynamic array as static data member

This topic is 2847 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

Hello GD! This is my first post here, nice to meet you all! Currently I'm taking baby steps into DirectX, and I have a question that I'm not sure if it fits into this forum...so admins please move it to the correct one if needed! Thanks!

I am making a game where a spaceship is flying through space avoiding asteroids. There are four kinds of asteroids, each differing in shape, and they are loaded in as meshes. I find that loading the mesh each time an asteroid is created is a waste of CPU, so I've decided to make a manager class for it. The manager class will be responsible for loading each mesh at runtime and passing out pointers to these meshes for each instance of the asteroid to be drawn. My first question is, is this approach appropriate?

And my second question, here's my code:

class AsteroidManager {
const static int NUM_MESHES = 4;

static LPD3DXMESH _mesh[NUM_MESHES];
static D3DMATERIAL9 **_materials;
static LPDIRECT3DTEXTURE9 **_textures;
static DWORD *_numMat;

static bool loadMeshes();

#inclulde "AsteroidManager.h"

LPD3DXMESH AsteroidManager::_mesh[NUM_MESHES];
D3DMATERIAL9 AsteroidManager::**_materials;
LPDIRECT3DTEXTURE9 AsteroidManager::**_textures;
DWORD AsteroidManager::*_numMat;

bool AsteroidManager::loadMeshes() {
_materials = new D3DMATERIAL9*[NUM_MESHES];
_numMat = new DWORD[NUM_MESHES];

// The rest goes here
// ...

return true;

loadMeshes is called during initialization of my game. When I compile my program, it gives:

error LNK2001: unresolved external symbol "private: static unsigned long * AsteroidManager::_numMat" (?_numMat@AsteroidManager@@0PAKA)
error LNK2001: unresolved external symbol "private: static struct IDirect3DTexture9 * * * AsteroidManager::_textures" (?_textures@AsteroidManager@@0PAPAPAUIDirect3DTexture9@@A)
error LNK2001: unresolved external symbol "private: static struct _D3DMATERIAL9 * * AsteroidManager::_materials" (?_materials@MeteorManager@@0PAPAU_D3DMATERIAL9@@A)

Am I declaring my variables correctly? Please guide me :(

Thanks alot for your time!

Share this post

Link to post
Share on other sites
The pointer asterisks go before the "AsteroidManager::" part. You are declaring pointers to members with your current setup.

LPD3DXMESH AsteroidManager::_mesh[NUM_MESHES];

D3DMATERIAL9 **AsteroidManager::_materials;

LPDIRECT3DTEXTURE9 **AsteroidManager::_textures;

DWORD *AsteroidManager::_numMat;

Also if all the arrays are going to share the same size consider grouping the data into a structure and having an array of that. Also, consider using std::vector<> rather than maintaining a pointer,count pair.

Finally such static data is usually a bad idea, but one step at a time for the moment, get it working and if you're interested about improving your design come back to us.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!