• Advertisement
Sign in to follow this  

Strange struct/vector problem

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

I have no idea what this problem is, ive tried everything. Maybe someone here can help. When i compile my program (Dev-C++) i get these errors: 10 C:\Documents and Settings\Kris2456\My Documents\Programming\Tankz\Map Editor\main.cpp In file included from main.cpp 45 C:\Documents and Settings\Kris2456\My Documents\Programming\Tankz\Map Editor\Header.h syntax error before `;' token C:\Documents and Settings\Kris2456\My Documents\Programming\Tankz\Map Editor\Makefile.win [Build Error] [main.o] Error 1 now this is the file: Haader.h, i have noted the place where the error is:
#ifndef HEADER_H_
#define HEADER_H_



extern HDC			hDC;		// Private GDI Device Context
extern HGLRC		hRC;		// Permanent Rendering Context
extern HWND		hWnd;		// Holds Our Window Handle
extern HINSTANCE	hInstance;
extern HWND  g_hWnd;		// Holds The Instance Of The Application

extern bool active;
extern bool fullscreen;
extern bool keys[256];
extern bool mouse[3];
extern int tiles[80][60];
extern int ActiveTile;
enum {WM_LMBUTTON,WM_RMBUTTON,WM_MMBUTTON};



void DrawGrid();
void TileMode();
void LoadTiles();
void SelectTile();
void DrawGUI();

void CreateBuilding();
void LoadBuildings();
void SelectBuilding();
void DrawBuildings();

void BuildFont(LPSTR strName, int size);
void KillFont();
void PrintText(const char *fmt, ...);

bool WriteMap();

typedef struct BUILDING
{
    POINT Origin,Outer,Origin2,Outer2;
    int Tex;
};

//COMPILER SAYS ERROR IS HERE!
extern vector<BUILDING> BuildList;


#endif

Share this post


Link to post
Share on other sites
Advertisement
Hopefully this will fix your problem:

typedef struct
{
POINT Origin,Outer,Origin2,Outer2;
int Tex;
} BUILDING;

or

struct BUILDING
{
POINT Origin,Outer,Origin2,Outer2;
int Tex;
};

You probably want to include the vector header at the top of your include file, and use the std:: namespace before the "vector" below...

Share this post


Link to post
Share on other sites
Doh, been a while since I posted.

I edited the post above somewhat. There are a few things I would try to fix anyway.

- Use of 'extern'. Do you really need to use global variables? It looks like you're using C++ from a C point of view.
- Not using the std:: namespace (std::vector). Are you using non-standard C++ headers or do you have a "using namespace std;" somewhere?

Pete

Share this post


Link to post
Share on other sites
Yes, looks like you're coming from a C background and using C++. You poor thing. :(

In C++, the "typedef struct" idiom is no longer needed, and should be avoided.

Also, within the header file, you will still need to #include <vector> in order for a vector declaration to be understood in the header. And since that class is in the std namespace, you will have to qualify it:


#ifndef HEADER_H_
#define HEADER_H_
#include <vector>
// rest of header
struct BUILDING {
POINT Origin,Outer,Origin2,Outer2;
int Tex;
};

extern std::vector<BUILDING> BuildList;
#endif


You probably have many more problems coming up because of the C background (things just aren't done the same way in modern C++, even though it lets you), but I won't pretend I can fix them just from your header file...

Share this post


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

  • Advertisement