Raea6789
Raea6789

Reputation: 141

including header files in one another

if I have two header files

a.h and b.h

can I include "a.h" in b.h

and also include "b.h" in "a.h" ?

Upvotes: 0

Views: 77

Answers (2)

sj95126
sj95126

Reputation: 6908

You can, but it's not a very good idea. If you really must, you can prevent recursion with the use of include guards (which are a good idea regardless).

In a.h:

#ifndef A_H
#define A_H

#include "b.h"

#endif

and b.h

#ifndef B_H
#define B_H

#include "a.h"

#endif

Upvotes: 1

Bananenkönig
Bananenkönig

Reputation: 543

No that won't work. The preprocessor just replaces your #include"xyz.h" with the actual file, so this would end in an endless recursion.

Upvotes: 0

Related Questions