Header Issues

Hello, I'm trying to create a simple game using MFC and I decided to better organize the parts of my game using seperate class objects, however, they are causing some issues for me, they need to reference each other in multiple places, so I decided to create a "central" header file named resource.h that references all of them, and creates their pointers, however, this is causing errors.

This is the resource.h file:

1
2
3
4
5
6
7
8
9
10
11
#pragma once //only run this one time

#include <afxwin.h>
#include "Enemy.h"
#include "Gun.h"
#include "Game.h"
#include "MFCGame1.h"

Enemy *hostile = new Enemy();
Gun *pistol = new Gun(1);
Game *game = new Game();


Generates 4 errors per the definition lines:
1
2
3
4
1>c:\users\robert\documents\visual studio 2008\projects\amfcgame\amfcgame\requires.h(10) : error C2143: syntax error : missing ';' before '*'
1>c:\users\robert\documents\visual studio 2008\projects\amfcgame\amfcgame\requires.h(10) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\robert\documents\visual studio 2008\projects\amfcgame\amfcgame\requires.h(10) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\robert\documents\visual studio 2008\projects\amfcgame\amfcgame\requires.h(10) : error C2061: syntax error : identifier 'Gun'


I've tried this too:
1
2
3
4
5
6
7
8
9
10
11
#pragma once //only run this one time

#include <afxwin.h>
#include "Enemy.h"
#include "Gun.h"
#include "Game.h"
#include "MFCGame1.h"

Enemy *hostile;
Gun *pistol;
Game *game;


I know that at some point I can simply use extern in the other files to reference these global objects, but how can I properly create all of these in the header file?
Last edited on
Never mind, I added some macros to define when the headers could be loaded and it runs fine.
Topic archived. No new replies allowed.