why isn't this working?
I am trying to set my new project like the article by Chris Hargrove that appeared here at gamedev a few months ago. He had all his global variables in one file called globals.h (or something like that), his main windows message loop and such in a file called main.cpp, another header file for a class called creature.h and a file for the class called creature.cpp. In globals.h he included creature.h, the global variables, definitions, etc. In creature.cpp he included globals.h. All the global variables in globals.h had the extern keyword infront of them. He also declared the same variables in main.cpp without the extern keyword in front of them.
I am trying to get a similar setup running. My main message loop is called lightworks.cpp, my globals are kept in globals.h (with the extern keyword). My one header file (which is included in globals.h) is called functions.h, and last but not least there is the corresponding file functions.cpp, which includes globals.h. I cant seem to get things to work. Here is the first part of each file:
lightworks.cpp:
#include "globals.h"
LPDIRECT3D8 g_pD3D = NULL; // Used to create the D3DDevice
LPDIRECT3DDEVICE8 g_pd3dDevice = NULL; // Our rendering device
globals.h:
#include
#include
#include
#include "functions.h"
//-----------------------------------------------------------------------------
// Global variables
//-----------------------------------------------------------------------------
extern LPDIRECT3D8 g_pD3D = NULL; // Used to create the D3DDevice
extern LPDIRECT3DDEVICE8 g_pd3dDevice = NULL; // Our rendering device
functions.h:
nothing
functions.cpp:
#include "globals.h"
Can anyone figure out what I am doing wrong? I have no clue (since this is only the second time I''ve tried this).
"Never pet a burning dog." - Warcraft II
It is telling me that I already declared the two global variables. I am also not sure if I need to include anything in functions.cpp. Any hints on this?
"Never pet a burning dog." - Warcraft II
"Never pet a burning dog." - Warcraft II
Aha - this might be it.
At the top of each header file, put this:
#ifndef NAME_OF_HEADER
#define NAME_OF_HEADER
then at the bottom:
#endif
This will stop multiple inclusion, and hopefully will fix your problem.
At the top of each header file, put this:
#ifndef NAME_OF_HEADER
#define NAME_OF_HEADER
then at the bottom:
#endif
This will stop multiple inclusion, and hopefully will fix your problem.
quote:
Original post by Quantum
Aha - this might be it.
At the top of each header file, put this:
#ifndef NAME_OF_HEADER
#define NAME_OF_HEADER
then at the bottom:
#endif
This will stop multiple inclusion, and hopefully will fix your problem.
Couldn''t he replace this with
|
at the top of each header?
==========================================In a team, you either lead, follow or GET OUT OF THE WAY.
quote:
Original post by NuffSaid
Couldn''t he replace this with
|
at the top of each header?
Yeah, but I like the other way better
Darn it. The #pragma once didn''t work. I was supposed to put in in every header file was I? Am I supposed to include any files in my functions.cpp?
I think I might have to e-mail Ben Dilts about this one again, but I would prefer if I didn''t have to pester him again.
"Never pet a burning dog." - Warcraft II
I think I might have to e-mail Ben Dilts about this one again, but I would prefer if I didn''t have to pester him again.
"Never pet a burning dog." - Warcraft II
Ok, try this:
|
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement