Circular including, help!!

J

jalkadir

Check this out... file foo.hpp includes bar.hpp, but bar.hpp includes
foo.hpp.
The compiler/linker is having a lot of problem resolving this problem.
Does anyone know if there is a way to solve this problem.

TIA
 
P

__PPS__

You may use header duards (or whatever to call them) like these:

file foo.hpp:

#ifndef _FOO_HPP_
#define _FOO_HPP_
.... dontents of foo.hpp goes here
#endif /* _FOO_HPP_ */


file bar.hpp:

#ifndef _BAR_HPP_
#define _BAR_HPP_
.... dontents of bar.hpp goes here
#endif /* _BAR_HPP_ */


and now you may include any of them in any order any number of times,
but the code will be included only once
 
P

__PPS__

__PPS__ said:
You may use header duards (or whatever to call them) like these:

guards I meant :)

you may see that inclusion of foo.hpp defines macro _FOO_HPP_, the next
time this header included once again _FOO_HPP_ will be defined and the
entire contents of it will be skiped, that's how it works. Same thing
happens with _BAR_HPP_ ...
 
M

Marcus Kwok

__PPS__ said:
You may use header duards (or whatever to call them) like these:

file foo.hpp:

#ifndef _FOO_HPP_
#define _FOO_HPP_
... dontents of foo.hpp goes here
#endif /* _FOO_HPP_ */


file bar.hpp:

#ifndef _BAR_HPP_
#define _BAR_HPP_
... dontents of bar.hpp goes here
#endif /* _BAR_HPP_ */

Yes, but names starting with an underscore followed by a capital letter
are reserved for the implementation (also, names starting with two
underscores). You should remove them, like FOO_HPP and BAR_HPP.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,679
Members
48,796
Latest member
Greg L.

Latest Threads

Top