Advertisement

header files

Started by December 29, 2002 07:52 PM
0 comments, last by hibikikonzaki 21 years, 10 months ago
ok, i've got a header file that I want to include in multiple source files, but I get link errors. I use #ifndef and stuff, but it still gives me errors.
      
#ifndef _Global
#define _Global


#include <Windows.h>
#include <fstream.h>
#include <d3dx9.h>
#include <d3d9.h>
#include "dxutil.h"
#include "D3DFont.h"
#include "D3DUtil.h"
#include "d3dfile.h"
#include "dsutil.h"
#include "diutil.h"
#include "input.h"

#define KEYDOWN(name,key) ((name[key] & 0x80) ? true : false)
#define KEYUP(name,key) ((name[key] & 0x80) ? false : true)

#define WINDOW_CLASS_NAME "Engine"
#define SCREEN_HEIGHT 600
#define SCREEN_WIDTH 800

extern int Game_Init();
extern int Game_Shutdown();

class CMainWnd
{
public:
	HWND      main_window_handle; // globally track main window

	HINSTANCE hinstance_app;
	
	CMainWnd()
	{
		main_window_handle = NULL;
		hinstance_app = NULL;
	}

	int Error_Message(char *Message);

};

class CDXMouse;
class CDXInput;
class CDXKeyboard;

CMainWnd Window;

#endif
  
I thought #ifndef and stuff would work. Thanks. I've also looked through Google, and from what I've found this should work. Hibiki Wheres the any key? www.geocities.com/dragongames123/home.html INSERT MY OVER-SIZED EXTRAVOGENT PIC HERE: [edited by - HibikiKonzaki on December 29, 2002 10:27:11 PM]
HibikiWheres the any key?www.geocities.com/dragongames123/home.htmlINSERT MY OVER-SIZED EXTRAVOGENT PIC HERE:
In your header file you create an instance of the class CMainWnd called Window - "CMainWnd Window;" now when you include the header file the object file produced contains a variable Window of type CMainWnd. however if you include the header in another source file then the resulting object file also contains a CMainWnd Window. when the object files are linked the linker doesnt know which Window to use because the variable exists more than once.

the solution is to define it in a cpp file and make it an extern in the header, if it needs to be accessed from multiple files.

This topic is closed to new replies.

Advertisement