Register    Login    Forum    Search    FAQ

Board index » Everything




Post new topic Reply to topic  [ 54 posts ]  Go to page Previous  1, 2, 3, 4, 5, 6
Author Message
 Post Posted: August 31st, 2017, 1:54 am 
 

Joined: February 28th, 2013, 3:23 am
Posts: 2908
Location: Oklahoma, United States
Lol, cheers

_________________
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


Top 
 Profile  
Reply with quote  
 Post Posted: January 6th, 2018, 6:17 pm 
 

Joined: January 6th, 2018, 5:31 pm
Posts: 2
After spending a couple of hours struggling with errors, I decided to post to this thread to request assistance. Just after resolving to do so, I fixed my problem, so I thought I would post anyways in case someone else was having the same issue.

While working through tutorial 14b, I finally got the goal class defined and implemented, but upon building, I was met with several errors pointing to goal.h and stating:
Quote:
missing type specifier - int assumed.

I checked and rechecked that all was correct in the goal.h, then turned to Google where I discovered from the following stack overflow post (https://stackoverflow.com/questions/23283080/compiler-error-c4430-missing-type-specifier-int-assumed) that the error is a result of something called circular dependency. This pointed me towards my various #include tags. After scouring the tutorial video and combing through the .h files, I realized that Chili's Snake.h file only had:
Code:
#include "Board.h"
whereas my Snake.h file had:
Code:
#include "Board.h"
#include "Location.h"
#include "Colors.h"
#include "Food.h"
The extra included header files were probably leftover from my efforts to figure out the snek game myself. Removing the extras immediately fixed all the errors.

I hope this helps anyone who may have struggled with this too. For those reading this who are more knowledgeable than I am, would you clarify why simply including unnecessary .h files causes the program to break? Furthermore, why does Chili only include Location.h in Board.h despite having location data members in many other header files? It makes sense to me that a header file should know about Location.h if they are going to have location objects. Or is it that they DO know about Location.h because all of them are included in Game.h? Thank you for your help!


Top 
 Profile  
Reply with quote  
 Post Posted: January 6th, 2018, 9:27 pm 
 

Joined: February 28th, 2013, 3:23 am
Posts: 2908
Location: Oklahoma, United States
The header files are copy pasted everywhere they are included, and it is recursive. If Board.h includes Location.h, then any file that includes Board.h knows about the Location class. Which means Location.h is copied and pasted to Board.h and then Board.h is pasted to Snek.h with the Location.h contents. All of that is copied to the Snek.cpp file so that you can use the Location class and Board class inside Snek.

This should help figure out why circular dependencies wreck your program. If you include Snek.h in Food.h and Food.h in Snek.h, when does the compiler know when to quit making copies of each? Granted, the #pragma once should stop this behavior, but it doesn't.

_________________
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


Top 
 Profile  
Reply with quote  
 Post Posted: January 7th, 2018, 5:43 am 
 

Joined: January 6th, 2018, 5:31 pm
Posts: 2
That makes so much sense. Thank you very much!


Top 
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
 
Post new topic Reply to topic  [ 54 posts ]  Go to page Previous  1, 2, 3, 4, 5, 6

Board index » Everything


 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
cron