Build errors

The Partridge Family were neither partridges nor a family. Discuss.
User avatar
Yumtard
Posts: 575
Joined: January 19th, 2017, 10:28 pm
Location: Idiot from northern Europe

Build errors

Post by Yumtard » January 31st, 2017, 4:53 am

I'm getting a ton of these, what do they mean?

chili_framework\engine\energyboost.h(10): error C2061: syntax error: identifier 'Ship' (compiling source file Main.cpp)

albinopapa
Posts: 4373
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: Build errors

Post by albinopapa » January 31st, 2017, 5:02 am

Well, either energyboost.h doesn't include ship.h OR you have energyboost.h including ship.h AND ship.h includes energyboost.h

Can't include A into B and B into A, it's called a circular dependency.
Chili covers this in one of his vids.
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com

albinopapa
Posts: 4373
Joined: February 28th, 2013, 3:23 am
Location: Oklahoma, United States

Re: Build errors

Post by albinopapa » January 31st, 2017, 5:08 am

Or it means you have forward declared Ship; class Ship and are trying to use it or store it as an object in energyboost.h somewhere. In order to forward declare a class, you can only
store a reference or pointer in the class that needs it
or
pass by reference or pointer to a function that uses it

For instance, if EnergyBoost wants to know about Ship but Ship.h already #includes EnergyBoost.h then you can forward declare Ship ( class Ship; ) at the top of energyboost.h above the class declaration. Then you can pass the Ship by reference to the functions. You must however, then #include sihp.h in energyboost.cpp.
If you think paging some data from disk into RAM is slow, try paging it into a simian cerebrum over a pair of optical nerves. - gameprogrammingpatterns.com

User avatar
Yumtard
Posts: 575
Joined: January 19th, 2017, 10:28 pm
Location: Idiot from northern Europe

Re: Build errors

Post by Yumtard » January 31st, 2017, 5:30 am

I'm not seeing any of that. Energyboost includes ship but ship doesn't include energyboost
I'm getting tons of similar ones for energyboost and also for energyboostmanager and game.cpp

it also says
error C2660: 'MineManager::Update': function does not take 2 arguments
: error C2660: 'EnergyBoostManager::Update': function does not take 2 arguments
error C2660: 'MineManager::Draw': function does not take 2 arguments
error C2660: 'EnergyBoostManager::Draw': function does not take 2 arguments

even tho they all take 2 arguments

and also these
.h(18): error C3646: 'eBoost': unknown override specifier (compiling source file EnergyBoost.cpp)
energyboostmanager.h(18): error C2143: syntax error: missing ',' before '[' (compiling source file EnergyBoost.cpp)
energyboostmanager.h(18): error C2143: syntax error: missing ')' before ';' (compiling source file EnergyBoost.cpp)

even tho there seem to be no syntax errors

User avatar
Yumtard
Posts: 575
Joined: January 19th, 2017, 10:28 pm
Location: Idiot from northern Europe

Re: Build errors

Post by Yumtard » January 31st, 2017, 5:45 am

okay noticed something weird now
in game.h I have ship object, minemanager object and energyboostmanager object
in the header I have included all 3 ship.h minemanager.h and energyboostmanager.h
if I delete minemanager.h and ship.h nothing happens but if I delete energyboostmanager.h I can no longer make an object from that class

User avatar
chili
Site Admin
Posts: 3948
Joined: December 31st, 2011, 4:53 pm
Location: Japan
Contact:

Re: Build errors

Post by chili » January 31st, 2017, 5:47 am

hmmm, i just forked your repo and it builds fine. You should update your repo when asking for support, can make the process a lot smoother ;)
Chili

User avatar
Yumtard
Posts: 575
Joined: January 19th, 2017, 10:28 pm
Location: Idiot from northern Europe

Re: Build errors

Post by Yumtard » January 31st, 2017, 5:50 am

Sorry. I pushed it now, it's a complete train wreck lol

User avatar
chili
Site Admin
Posts: 3948
Joined: December 31st, 2011, 4:53 pm
Location: Japan
Contact:

Re: Build errors

Post by chili » January 31st, 2017, 5:57 am

Well sir, first glance I see that Mine.h includes Ship.h includes MineManager.h includes Mine.h includes Ship.h ....

You got yourself a nice circular dependency there ;)
Chili

User avatar
Yumtard
Posts: 575
Joined: January 19th, 2017, 10:28 pm
Location: Idiot from northern Europe

Re: Build errors

Post by Yumtard » January 31st, 2017, 6:03 am

chili wrote:Well sir, first glance I see that Mine.h includes Ship.h includes MineManager.h includes Mine.h includes Ship.h ....

You got yourself a nice circular dependency there ;)

ouff.. I'm fucked then? I can't delete any of these

User avatar
chili
Site Admin
Posts: 3948
Joined: December 31st, 2011, 4:53 pm
Location: Japan
Contact:

Re: Build errors

Post by chili » January 31st, 2017, 6:10 am

There are 2 solutions.

1) Preferred: Design your system to have a non-cyclic dependency tree. This is preferred, and it is what I am demonstrating in all of the examples I've given so far in the tutorials.
2) Forward Declaration: in the headers, usually the compiler doesn't need to know the details of a class, just that that class is a thing that exists, and the actual definition can be deferred until you get to to the .cpp file where the actual functions are defined and where the class is actually used.

Let me see if it is an easy solve.
Chili

Post Reply