# Classes

## Recommended Posts

Ok, in Player.cpp: #include "globals.h" class PLAYER { Some Player stuff like positions states etc. }; and then in globals.h PLAYER *Player; I do this with other classes as well but when it comes to compiling... globals.h(112) : error C2143: syntax error : missing ';' before '*' globals.h(112) : error C2501: 'PLAYER' : missing storage-class or type specifiers globals.h(112) : error C2501: 'Player' : missing storage-class or type specifiers I dunno what's wrong, I've created the class correctly and I'm pretty sure I'm creating the instance right so what's wrong?

##### Share on other sites
Well you're trying to use a class that doesn't exist yet as far as the compiler is concerned. "globals.h" comes before you're declaration of PLAYER so the code to the compiler looks like this:

PLAYER *Player; // <- PLAYER, what's that?class PLAYER{Some Player stuff like positions states etc.};

try this:

// globals.hclass PLAYER; // <- Now at least we now it exists someplacePLAYER *Player; // Player.cpp#include "globals.h"class PLAYER{Some Player stuff like positions states etc.};

( why is this in DirectX? )

##### Share on other sites
Note that you also want to declare the global "extern" in the header so that you don't get multiple copies defined.

Anyway, it doesn't make much sense to declare a global of an unknown type in a header, because nobody else can actually use it (you have to know the class declaration to use it). I'd suggest the normal strategy of:

// player.hclass PLAYER {  void SomeFunc();  // declaration  ... declarations ...};extern PLAYER * gPlayer; // declaration// player.cpp#include "player.h"PLAYER * gPlayer; // definitionvoid PLAYER::SomeFunc() // definitions{  ...}

##### Share on other sites
Also, I'm moving this to For Beginners, as it has nothing to do with DirectX.

##### Share on other sites
Oh yeah sorry about that my mistake.
And I'll try those things out, thanks.

##### Share on other sites
Ok I have a few more questions, first:
In Main.cpp I have:

D3DXMatrixLookAtLH(&ViewMat, &D3DXVECTOR3(player.x, player.y, camz), &D3DXVECTOR3(x, y, 0.0f), &D3DXVECTOR3(0.0f, 1.0f, 0.0));

which gives these errors:
main.cpp(315) : error C2065: 'x' : undeclared identifier
main.cpp(315) : error C2065: 'y' : undeclared identifier

but yet in Player.h insed the PLAYER class:

float x; //The X position of the player
float y; //The Y position of the player

So why is it saying they arn't declared?

Secondly in Tile.CPP I get this error:

error C2275: 'TILE' : illegal use of this type as an expression

from this line:
D3DXMatrixTranslation(&WorldMat, TILE.x, TILE.y, 0.0f);

So could anyone point me in the right direction?
I would also like to say this is my first real attempt at using a more Object Orientated programming style in an application.

##### Share on other sites
Quote:
 Original post by Dom_152Ok I have a few more questions, first:In Main.cpp I have:D3DXMatrixLookAtLH(&ViewMat, &D3DXVECTOR3(player.x, player.y, camz), &D3DXVECTOR3(x, y, 0.0f), &D3DXVECTOR3(0.0f, 1.0f, 0.0));which gives these errors: main.cpp(315) : error C2065: 'x' : undeclared identifiermain.cpp(315) : error C2065: 'y' : undeclared identifierbut yet in Player.h insed the PLAYER class:float x; //The X position of the playerfloat y; //The Y position of the playerSo why is it saying they arn't declared?

D3DXMatrixLookAtLH(&ViewMat, &D3DXVECTOR3(player.x, player.y, camz), &D3DXVECTOR3(player.x, player.y, 0.0f), &D3DXVECTOR3(0.0f, 1.0f, 0.0));

Quote:
 Secondly in Tile.CPP I get this error:error C2275: 'TILE' : illegal use of this type as an expressionfrom this line:D3DXMatrixTranslation(&WorldMat, TILE.x, TILE.y, 0.0f);So could anyone point me in the right direction?I would also like to say this is my first real attempt at using a more Object Orientated programming style in an application.

Is TILE a class or an instance? If you only want to use a class once then you might want to look into singletons. Remember that you can't do PLAYER.x, it has to be player.x. PLAYER only describes the class, player is an actual instance of PLAYER.

You might want to research OO techniques a little more and become familiar with error meesages(that first one should have been easy to spot), before moving on with DX.

##### Share on other sites
Ah yes, I must be blind... Well I am visually impaired ;)
And I guess I could change TILE to Tiles[] which is an array of TILE
Edit: Aha yes I know what I'll do now I can copy the contents of the current tile in teh array being rendered e.g. Tiles[4] to the temporary TILE instance tile. Well it makes sense to me if not to anyone esle. :)