I’ve got problem while including header files, in every header file i use
#pragma once
File structure:
Main.cpp
- includes
Main.h
class definition
Main.h
- includes
"class.h"
"random_header.h"
others ( windows , fstream )
class declaration
Class.h
- includes
"Main.h"
class cApplication{ };
Other headers ( class, random_header ) include Main.h
errors in Main.h at class declaration:
error C2146: syntax error : missing ';' before identifier 'App' ( App is class name )
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
I’ll be thankfull for any help/tips.
Main.h code
#pragma once
#pragma comment (lib, "d3d9.lib")
#pragma comment (lib, "d3dx9.lib")
#include <Windows.h>
#include <d3d9.h>
#include <d3dx9.h>
#include <fstream>
using namespace std;
#include "D3Ddefs.h"
#include "cApplication.h"
extern cApplication App; //error
LRESULT CALLBACK WindowProcedure(HWND,UINT,WPARAM,LPARAM);
Ok, theres more code as you asked, in my opinion posting whole thing is a bit pointless (if it isn’t, tell me please), so I’ll just add this what should be important.
Main.cpp
#include "Main.h"
cApplication App;
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPreviousInstance,LPSTR lpcmdline,int nCmdShow)
{ ... }
D3Ddefs.h ( full )
#pragma once
#include "Main.h"
#define D3DFVF_CUSTOMVERTEX (D3DFVF_XYZ | D3DFVF_DIFFUSE)
struct D3DVERTEX
{
float fX,
fY,
fZ;
DWORD dwColor;
};
cApplication.h
#pragma once
#include "Main.h"
class cApplication
{
private:
...
};
cApplication.cpp
#include "cApplication.h"
cApplication::cApplication(void)
{ ...
}
What you have is a circular inclusion issue. Manually replace each of those #includes with the file they include’s content, in the order they happen, ignoring any file that was previously include, and you’ll see that, in cApplication.cpp, “extern cApplication App;” happens above the declaration of cApplication.
As to how to solve this? Can’t actually tell you without knowing why cApplication.h needs Main.h. If you can separate that dependency out, you should be alright. Are you trying to make cApplication some kind of singleton, including Main.h so you can access that “App” variable?