Strange struct/vector problem

Started by
3 comments, last by Zahlman 19 years, 3 months ago
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

------------ "Here lies a toppled God,His fall was not a small one,We but built his pedastle,A narrow, and a tall one" Frank Herbert (Dune:Messiah)
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...
no, same error.

By the way, use square ([) brackets for those things.
------------ "Here lies a toppled God,His fall was not a small one,We but built his pedastle,A narrow, and a tall one" Frank Herbert (Dune:Messiah)
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
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 headerstruct 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...

This topic is closed to new replies.

Advertisement