Click here to Skip to main content
15,917,061 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
typedef struct NOTEPAD_GLOBALS;

typedef struct 
 {
  HINSTANCE hInstance;
  HWND    hMainWnd;
}NOTEPAD_GLOBALS;

extern NOTEPAD_GLOBALS Globals;


This is my def.h when I #include it in only main.c it works fine, but when I #include it in the main.h, as well, it gives me this error.

def.h(12) : error C2371: 'NOTEPAD_GLOBALS' : redefinition; different basic types<br />
def.h(12) : see declaration of 'NOTEPAD_GLOBALS'


I have no idea what is wrong with it. Any help would be greatly appreciated. I am using Visual C++ 6
Posted

1 solution

You should add the directive

#pragma once


at the top of your header.

If VC6 compiler doesn't support it (I don't remember...), use the oldie goldie #if !defined(), for instance:

#if !defined( __MYHEADER__)
#define __MYHEADER__

typedef struct NOTEPAD_GLOBALS;

typedef struct 
 {
  HINSTANCE hInstance;
  HWND    hMainWnd;
}NOTEPAD_GLOBALS;

extern NOTEPAD_GLOBALS Globals;

#endif// __MYHEADER__


These meachanism avoid multiple inclusion issues.
:)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900