Header files that call each other
How do you guys explain header files that call on each other?
Would it result in a infinate loop or just once?
Enclose all your headers with #ifndefs, like this:
Foo.h:
#ifndef FOO_H
#define FOO_H
#endif // FOO_H
That way, they will only be included once per compile.
Or, a VC++ specific solution is:
#pragma once
Foo.h:
#ifndef FOO_H
#define FOO_H
#endif // FOO_H
That way, they will only be included once per compile.
Or, a VC++ specific solution is:
#pragma once
The technique Qoy specified is most widely used.
In the beginning of each header file:
#ifndef HEADERFILENAME_INCLUDED
#define HEADERFILENAME_INCLUDED
And in the end of the file:
#endif // HEADERFILENAME_INCLUDED
In the beginning of each header file:
#ifndef HEADERFILENAME_INCLUDED
#define HEADERFILENAME_INCLUDED
And in the end of the file:
#endif // HEADERFILENAME_INCLUDED
is it the " _ " (underscore) the significate here?
let''s say we have a file myHeader.h
#ifndef myHeader.h_INCLUDED
#def myHeader.h_INCLUDED
#endif
let''s say we have a file myHeader.h
#ifndef myHeader.h_INCLUDED
#def myHeader.h_INCLUDED
#endif
the underscore is not significant
you could just have
#ifndef MYFILE
#define MYFILE
#endif
but you generally use the filename so if your filename is myfile.h
you use
#ifnedf MYFILE_H
#define MYFILE_H
#endif
but it isnt required
"Now go away or I shall taunt you a second time"
- Monty Python and the Holy Grail
themGames Productions
you could just have
#ifndef MYFILE
#define MYFILE
#endif
but you generally use the filename so if your filename is myfile.h
you use
#ifnedf MYFILE_H
#define MYFILE_H
#endif
but it isnt required
"Now go away or I shall taunt you a second time"
- Monty Python and the Holy Grail
themGames Productions
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement