I'm a fairly new programmer and i'm making a small game project in Visual Studio / C++ / SDL. So I have my code laid out like this:
prototypes.h:
#ifndef PROTOTYPES_H
#define PROTOTYPES_H
#include "constants.h"
#include "globals.h"
#include "functions.h"
struct circle
{
float x;
float y;
int r;
};
//other class declarations
#endif PROTOTYPES_H
functions.h:
#ifndef FUNCTIONS_H
#define FUNCTIONS_H
#include "SDL_header.h"
#include "prototypes.h"
bool check_collision(circle circle, SDL_Rect rect);
//other function declarations
#endif FUNCTIONS_H
Which as far I can tell is completely correct, at least according to this explanation. Even when I mouseover the 'circle' in the functions.h file in the IDE I get the correct tooltip 'struct circle' pop up. However when i compile I get the error 'undeclared identifier 'circle'' in reference to functions.h...
what the hell..?
You currently have a circular inclusion. Prototype.h includes functions.h and functions.h includes prototype.h
Now if a cpp file you are compiling calls prototype.h first the second line will include the content of functions.h which will place a reference to circle struct before its actual definition.
In your case if functions.h includes functions on structures defined in prototype.h there should not be any reason to include functions.h from prototype.h. If you manage the dependencies between header files your code will be much easier to manage..
In your case:
Also, it is usually worthwhile to keep the class/struct and all its functions in a single header file. Unless the file becomes too big in which case you can split functions it into multiple headers.
NOTE: A brute force solution can be to add a forward declaration to struct circle just before its usage in functions.h however I would reserve such solutions only for cases where they really can't be avoided