how to not fuck up #includes and sgit

The Partridge Family were neither partridges nor a family. Discuss.
Post Reply
holmrekR
Posts: 1
Joined: March 29th, 2017, 10:01 am

how to not fuck up #includes and sgit

Post by holmrekR » March 29th, 2017, 10:06 am

since i have had prior programmingsment experience, when watching the tutorials i like to try and code a bit ahead

however, for example when I did the snek game i ran into problems, and google told me it was about a file including a file, which includes itself and the compiler errors so it doesnt go into an ant circle of death

ive just been trying to #include things in the files when i want the certain files but sometimes it fucks up

how 2 not fuckup the includes

User avatar
Zedtho
Posts: 189
Joined: February 14th, 2017, 7:32 pm

Re: how to not fuck up #includes and sgit

Post by Zedtho » March 29th, 2017, 10:56 am

If there is a loop (for example, I included Dude.h in Game.h and vise versa once) it won't work.
If it's a file that is included multiple times (f. ex graphics in Dude and Game, which includes dude) you can use "#pragma once "
in the header files.

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

Re: how to not fuck up #includes and sgit

Post by chili » March 29th, 2017, 11:49 am

Yo holm, nice job googling that shit and getting an idea for yourself. For the snek game, write your code that that there are no depencency cycles. I.e. game knows about board, snake, segment, snake knows about board and segment, segment knows about board, and board don't know about shit (except location, which everybody knows). So segment doesn't know what a snake is, and snake doesn't know what game is, etc. etc.

Later on, in tutorial 18 (i think), i teach you the actualy mechanism of why #include cycles fuck you up, and then in a later tutorial (21 or 22) I teach you a way around that, when you really need two things to know about each other.
Chili

Post Reply