Problem with stacked "#include"s

Hi!
I have a really small problem but no idea how to solve it.

So i have three classes "Polygon", "Surface" and "Edge".
All three of those classes need
 
#include "mathematics.h" 

in their header file because their declarations use a 4th class defined there.

Now "Polygon" itself also needs "Surface" and "Edge" in its header file, because it uses those.
But as soon as I double-include "mathematics.h" I get a ton of errors, starting with "redefinition".

My only solution would be to put all classes in one file, but then I would always include more than I need and the code would get messy.

How do I solve this smartly?
> As soon as I double-include "mathematics.h" I get a ton of errors
Why did you double-include "mathematics.h" in a source file? Am I wrong?
To clarify:
in "Polygon.h" i need this:
1
2
#include "Edge.h"
#include "Surface.h" 


and in "Surface.h" i need:
 
#include "mathematics.h" 


and in "Edge.h" i need it as well:
 
#include "mathematics.h" 


That doesnt compile for me using Visual studios 2015. If i take out either

 
#include "Surface.h" 

or

 
#include "Edge.h" 


it works, but i need both classes.
Firstly, you need to add some guard macros.

1
2
3
4
5
6
#ifndef MATHEMATICS_H
#define MATHEMATICS_H

// The rest of code in mathematics.h

#endif 
Thank you, now it works.

If I get the code fragmet right, it just does a ifclause for the compiler that skips the code if its already defined?
Yes :)
Glad it helped :)
thanks! <3
Topic archived. No new replies allowed.