Jump to content
  • Advertisement
Sign in to follow this  
Ksingh30

classes

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

ok I have this weird problem, chances are im doing something wrong. I have a class Terrain, then a class Game. and in the private: of class game, im trying to do this "Terrain* main;" but I get these errors: c:\Documents and Settings\Kevin\Desktop\V3\Game.h(22) : error C2143: syntax error : missing ';' before '*' c:\Documents and Settings\Kevin\Desktop\V3\Game.h(22) : error C2501: 'game::Terrain' : missing storage-class or type specifiers c:\Documents and Settings\Kevin\Desktop\V3\Game.h(22) : error C2501: 'game::main' : missing storage-class or type specifiers

Share this post


Link to post
Share on other sites
Advertisement
nope. I can declare "Terrain* Main" in one of the method functions of class game. but I need to use "Terrain Main" in multiple functions of class game, so I was declaring "Terrain* Main" in the private section, but I get those errors. kinda weird.

Share this post


Link to post
Share on other sites
ok heres the class Game

#ifndef __gameH__
#define __gameH__

#include "engine.h"
#include "Input.h"
#include "Terrain.h"

class game{

private:

enum GameState{inGame,mainMenu,inGameMenu, Settings,inGameExit,Exit, None};
int windowWidth, windowHeight;
int currentState;
IDirect3DDevice9* _device;
Camera TheCamera;
bool mouseclick0, mouseclick1, mouseWheelUp, mouseWheelDown;
D3DXMATRIX V;
D3DXMATRIX scale;
D3DXMATRIX proj;
Input* keyMouse;
Terrain* main;





public:
game();
~game();
void run();
void stop();
void setDevice(IDirect3DDevice9* Device);
void mainMenuGui();
void inGameMenuGui();
void settingsGui();
void exitFunc();
void initialize();
void inGameExitFunc();
void ReleaseDevice(){_device->Release();}


};

#endif


and heres the class Terrain



#ifndef __TerrainH__
#define __TerrainH__

#include "engine.h"
#include <string>
#include <vector>

class Terrain
{
public:
Terrain(
IDirect3DDevice9* device,
std::string heightmapFileName,
int numVertsPerRow,
int numVertsPerCol,
int cellSpacing, // space between cells
float heightScale);

~Terrain();

int getHeightmapEntry(int row, int col);
void setHeightmapEntry(int row, int col, int value);

float getHeight(float x, float z);

bool loadTexture(std::string fileName);
bool genTexture(D3DXVECTOR3* directionToLight);
bool draw(D3DXMATRIX* world, bool drawTris);

private:
IDirect3DDevice9* _device;
IDirect3DTexture9* _tex;
IDirect3DVertexBuffer9* _vb;
IDirect3DIndexBuffer9* _ib;

int _numVertsPerRow;
int _numVertsPerCol;
int _cellSpacing;

int _numCellsPerRow;
int _numCellsPerCol;
int _width;
int _depth;
int _numVertices;
int _numTriangles;

float _heightScale;

std::vector<int> _heightmap;

// helper methods
bool readRawFile(std::string fileName);
bool computeVertices();
bool computeIndices();
bool lightTerrain(D3DXVECTOR3* directionToLight);
float computeShade(int cellRow, int cellCol, D3DXVECTOR3* directionToLight);

struct TerrainVertex
{
TerrainVertex(){}
TerrainVertex(float x, float y, float z, float u, float v)
{
_x = x; _y = y; _z = z; _u = u; _v = v;
}
float _x, _y, _z;
float _u, _v;

static const DWORD FVF;
};
};

#endif // __TerrainH__

Share this post


Link to post
Share on other sites
This is a classic recursive inclusion problem. You can get around it by forward declaring your Terrain class. In game.h put

class Terrain;


before your game class definition. This should allow it to declare a pointer to Terrain. For more details see this article.

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!