D
D
Dmitry Korolev2021-09-04 23:06:12
C++ / C#
Dmitry Korolev, 2021-09-04 23:06:12

How to use nested includes in headers and code?

I have a "base" header file which expands the structures, constants and prototypes for the header implementation file.
There is also a "complex" header file that uses these basic structures, constants and prototypes in its definitions of constants and prototype structures. The "complex" header is expanded for the header implementation file.
After including "complex" in the project's source code files, you should be able to use all of these definitions and functions.
How to do it? I'm confused about the inclusions.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
Wataru, 2021-09-04
@adressmoeistranici

Simple file Ah, complex Bh
Bh includes Ah Some C.cpp includes both Ah and Bh in any order. The trick is to use header guards. It's this thing:

#ifndef blablabla
#define blablabla

// определения

#endif // конец файла

Each file has its own unique bla-bla-bla (usually using a filename with a path). In this form, you can easily include any file a bunch of times and, as long as you do not have cyclic dependencies, an arbitrarily complex project is built - you just need to remember to always include everything that you use.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question