Feb 21, 2018 at 1:39pm UTC
Hello, the problem is, I'm not able to share the files I need, the compiler gives a disgusting and very annoying errors.
My first header file "Game.h" : (i'm only going to show you what it includes)
#include "SDL.h"
#include "Handler.h"
#include "Player.h"
My second header file "GameObject.h" :
#include "SDL.h"
#include "SDL_image.h"
#include <vector>
My third header file "Handler.h"
#include <vector>
#include "GameObject.h"
#include "Block.h"
#include <algorithm>
#include "GearDoor.h"
My fourth header file "Player.h"
#include "GameObject.h"
#include "Handler.h"
My fifth header file "Block.h"
#include "GameObject.h"
#include "Handler.h"
My sixth header file "GearDoor.h"
#include "GameObject.h"
//right here I want to include the file called "Handler.h"
//It does not give me an error, but as soon as I make a pointer to
//Handler, it starts giving me some huge errors.
//please someone help me, so I can finish making my game.
Last edited on Feb 21, 2018 at 1:47pm UTC
Feb 21, 2018 at 1:47pm UTC
Circular dependency.
You want GearDoor.h to depend on Handler.h, but Handler.h depends on GearDoor.h
There's some messy logic happening. You should probably think about on paper to figure what actually needs to include what.
Note that pointers can be declared after the class is declared, but before the implementation is. This is because the size of the pointer does not depend on the size of the class.
1 2 3 4 5 6 7 8
class A;
class B { A* a; };
class A {
void foo() {}
};
If you're still having troubles, post the
actual error messages (at least the first few), and relevant code lines.
Last edited on Feb 21, 2018 at 1:49pm UTC
Feb 21, 2018 at 1:52pm UTC
Sir, the errors are always the same, here :
Some lines Keep repeating
1>c:\users\hassa\source\repos\game\game\geardoor.h(3): warning C4067: unexpected tokens following preprocessor directive - expected a newline
1>c:\users\hassa\source\repos\game\game\geardoor.h(22): error C2143: syntax error: missing ';' before '*'
1>c:\users\hassa\source\repos\game\game\geardoor.h(22): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\hassa\source\repos\game\game\geardoor.h(22): error C2238: unexpected token(s) preceding ';'
1>Generating Code...
1>Compiling...
1>Game.cpp
1>c:\users\hassa\source\repos\game\game\geardoor.h(3): warning C4067: unexpected tokens following preprocessor directive - expected a newline
1>c:\users\hassa\source\repos\game\game\geardoor.h(22): error C2143: syntax error: missing ';' before '*'
1>c:\users\hassa\source\repos\game\game\geardoor.h(22): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\hassa\source\repos\game\game\geardoor.h(22): error C2238: unexpected token(s) preceding ';'
1>Generating Code...
1>Compiling...
1>GearDoor.cpp
1>c:\users\hassa\source\repos\game\game\geardoor.h(3): warning C4067: unexpected tokens following preprocessor directive - expected a newline
1>Generating Code...
1>Compiling...
1>main.cpp
1>c:\users\hassa\source\repos\game\game\geardoor.h(3): warning C4067: unexpected tokens following preprocessor directive - expected a newline
1>c:\users\hassa\source\repos\game\game\geardoor.h(22): error C2143: syntax error: missing ';' before '*'
1>c:\users\hassa\source\repos\game\game\geardoor.h(22): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\hassa\source\repos\game\game\geardoor.h(22): error C2238: unexpected token(s) preceding ';'
1>Player.cpp
1>c:\users\hassa\source\repos\game\game\geardoor.h(3): warning C4067: unexpected tokens following preprocessor directive - expected a newline
1>c:\users\hassa\source\repos\game\game\geardoor.h(22): error C2143: syntax error: missing ';' before '*'
1>c:\users\hassa\source\repos\game\game\geardoor.h(22): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\hassa\source\repos\game\game\geardoor.h(22): error C2238: unexpected token(s) preceding ';'
1>Handler.cpp
1>c:\users\hassa\source\repos\game\game\geardoor.h(3): warning C4067: unexpected tokens following preprocessor directive - expected a newline
1>c:\users\hassa\source\repos\game\game\geardoor.h(22): error C2143: syntax error: missing ';' before '*'
1>c:\users\hassa\source\repos\game\game\geardoor.h(22): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\hassa\source\repos\game\game\geardoor.h(22): error C2238: unexpected token(s) preceding ';'
1>Generating Code...
1>Skipping... (no relevant changes detected)
1>GameObject.cpp
1>Done building project "Game.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Feb 21, 2018 at 1:55pm UTC
So you are saying that, instead of having all the include files in the .h, i have it in the .cpp?
Feb 21, 2018 at 2:50pm UTC
Any file, header or source, should ONLY include a header if it's needed in that file. Needed.