c++ - Circularly declaring Preprocessor directives? Or defines before includes? -
I'm a bit new in C ++, so stay with me I'm trying to figure out that my project Where to place my #defines
and #includes
in I have something like this:
main.h
#include "other.h" #define MAX_GROUPS 100 Straight Cat {int somewhat [MAX_GROUPS]; }
I need to use MAX_GROUPS
, so if I also MAX_GROUPS
I also define other.h
like this:
Other .h
#define MAX_GROUPS 100 Street other {IT Taco [MAX_GROUPS]; }
The problem is that I am constantly defining more than one location. I want to keep it all together.
Alternatively, can I reinclude main.h
?
other.h
#include "main.h" straighten the other {Inte Taco [MAX_GROUPS]; }
The problem here is that I think this is made like a circular dependency also includes main.h
in other.h
Which includes main.h
which contains other.h
, which contains etc.
What is the best way to set up and it is included in a project so that things can be cascade in other included files? Is it common for you to define all before you join your own?
Reducing circular dependence is very important to maintain your project For extended discussion, by John Lukeos See "Large scale C ++ software design"
To avoid a specific problem, define values in a header file, and include the header file in that file, which is required. Use guards to avoid problems with many definitions:
#ifndef HEADER_THING_H #define HEADER_THING_H / * left header file goes here * / #endif
In this way, if it is already included, then it is harmless.
Comments
Post a Comment