I am having the usual errors within header files, as listed below.
Error 54 error C3083: 'Resources': the symbol to the left of a '::' must be a type e:\users\nkosi\documents\visual studio 2010\projects\directx games\direct2d\dx2dhelper\dx2dhelper\sprite.h 28 1 DX2DHelper
Error 55 error C2039: 'DX2DImage' : is not a member of 'DX2DHelper' e:\users\nkosi\documents\visual studio 2010\projects\directx games\direct2d\dx2dhelper\dx2dhelper\sprite.h 28 1 DX2DHelper
Error 56 error C2061: syntax error : identifier 'DX2DImage' e:\users\nkosi\documents\visual studio 2010\projects\directx games\direct2d\dx2dhelper\dx2dhelper\sprite.h 28 1 DX2DHelper
Error 57 error C3083: 'Resources': the symbol to the left of a '::' must be a type e:\users\nkosi\documents\visual studio 2010\projects\directx games\direct2d\dx2dhelper\dx2dhelper\sprite.h 32 1 DX2DHelper
Error 58 error C2039: 'DX2DImage' : is not a member of 'DX2DHelper' e:\users\nkosi\documents\visual studio 2010\projects\directx games\direct2d\dx2dhelper\dx2dhelper\sprite.h 32 1 DX2DHelper
Error 59 error C2143: syntax error : missing ';' before '*' e:\users\nkosi\documents\visual studio 2010\projects\directx games\direct2d\dx2dhelper\dx2dhelper\sprite.h 32 1 DX2DHelper
Error 60 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int e:\users\nkosi\documents\visual studio 2010\projects\directx games\direct2d\dx2dhelper\dx2dhelper\sprite.h 32 1 DX2DHelper
Error 61 error C2061: syntax error : identifier 'GameBase' e:\users\nkosi\documents\visual studio 2010\projects\directx games\direct2d\dx2dhelper\dx2dhelper\systemclass.h 30 1 DX2DHelper
However, for the life of me, I can’t figure out what I am doing wrong. I know I’m probably missing a semi-colon or something, but I really can’t figure it out. All the header files are below.
DX2DHelper.h
#include "targetver.h"
#define WIN32_LEAN_AND_MEANheaders
// Windows Header Files:
#include <windows.h>
#include <iostream>
#include <D2D1.h>
#include <D2D1Helper.h>
#include <wincodec.h>
#include <D2DBaseTypes.h>
#include <D2Derr.h>
#define DLEX __declspec(dllexport)
#include "GameBase.h"
#include "SystemClass.h"
#include "DX2DImage.h"
#include "Sprite.h"
SystemClass.h
#ifndef SYSTEMCLASS_H
#define SYSTEMCLASS_H
#include "DX2DHelper.h"
namespace DX2DHelper
{
namespace Core
{
class SystemClass;
struct WindowOptions;
struct DLEX WindowOptions {};
class DLEX SystemClass
{
public:
bool Initialize(WindowOptions options, HINSTANCE hInst);
void Run(GameBase* game, DX2DInitOptions options);
private:
WindowOptions options;
};
}
}
#endif
DX2DImage.h
#ifndef DX2DIMAGE_H
#define DX2DIMAGE_H
#include "DX2DHelper.h"
namespace DX2DHelper
{
namespace Resources
{
class DX2DImage;
class DX2DImageLoader;
class DLEX DX2DImageLoader
{
public:
HRESULT LoadFromFile(char* filePath, DX2DImage* image);
};
class DLEX DX2DImage
{
public:
friend class DX2DImageLoader;
};
}
}
#endif
Sprite.h
#ifndef SPRITE_H
#define SPRITE_H
#include "DX2DHelper.h"
namespace DX2DHelper
{
namespace GameComponents
{
class DLEX Sprite
{
public:
void SetImage(DX2DHelper::Resources::DX2DImage* image);
private:
DX2DHelper::Resources::DX2DImage* image;
};
}
}
#endif
GameBase.h
#ifndef GAMEBASE_H
#define GAMEBASE_H
#include "DX2DHelper.h"
namespace DX2DHelper
{
namespace Core
{
class DLEX GameBase
{
public:
friend class SystemClass;
HRESULT Initialize(HINSTANCE hInst, HWND winHandle, struct DX2DInitOptions options);
};
struct DLEX DX2DInitOptions {};
}
}
#endif
If anyone could figure out the mistakes, I would be very grateful. I’ve been looking at the same files for probably close to an hour, hour and a half now, and I just can’t fix it.
Your headers have (many) include cycle(s). For example,
DX2DHelper.hincludesSprite.hincludesDX2DHelper.h. This is probably what’s causing your errors. This code isn’t Java, and those aren’t import statements:#includecycles totally kill compiles, even if you don’t get a compile error specifically stating so. Pick an acyclic order for your header files.I’d suggest that
DX2DHelper.hnot have any of the includes at the bottom.Sprite.hcould includeDX2DImage.h.Where your objects have cyclic dependencies (as is the case with
SystemClassandGameBase, for example), you’ll need another solution. Forward declare the dependent class without giving its full declaration, e.g. inSystemClass.hyou might add somewhere early:and similarly in in
GameBase.h:This can even be a good idea when there aren’t cyclic object dependencies involved — its usually an easy way around the type of header hell you’ve run into here. Of course, to get everything to compile, you’ll probably need to
#includethe appropriate headers in the corresponding implementation files. But, assuming you don’t#includeany of your.cpp/.ccfiles, this should allow everything to compile without the#includehell you’ve gotten yourself into.