Avoid includei in header files
-
Hi, I prefer not to include any header files in other header files as long as it is possible. But I have problem when I want to use an Enumeration type in a header file, which is defined in another header file. I mean we can introduce classes and structs at the start of a header file, but it is not the case about Enumeration Data Types: struct st1; //correct Class C1; //correct Enum e1; //Incorrect
-
Hi, I prefer not to include any header files in other header files as long as it is possible. But I have problem when I want to use an Enumeration type in a header file, which is defined in another header file. I mean we can introduce classes and structs at the start of a header file, but it is not the case about Enumeration Data Types: struct st1; //correct Class C1; //correct Enum e1; //Incorrect
is this a design question ? or just trying to inform somebody here ? if so, I strongly unadvise to do so. that is just not suitable for most advanced designs, and it's just the way C/C++ is designed and intended to work... so, to make it short, go with #includes withing headers, it's not bad to do so !
[VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]
-
is this a design question ? or just trying to inform somebody here ? if so, I strongly unadvise to do so. that is just not suitable for most advanced designs, and it's just the way C/C++ is designed and intended to work... so, to make it short, go with #includes withing headers, it's not bad to do so !
[VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]
I am not sure, but I think it is a good idea to do such a thing. Actually I avoid making circular includes in this way.
-
I am not sure, but I think it is a good idea to do such a thing. Actually I avoid making circular includes in this way.
reza matinnejad wrote:
I avoid making circular includes in this way
this CANNOT happen, as long as you designed your headers correctly. there is a multiple includes exclusion system which tells for the header which it's defined in not to include it more than once... If you're using Visual Studio only, the following is good and prefered for performances. This is MS specific:
//Beginning of the header file
#pragma once//...remaining of your file...
if your sources are portable on pultiple plateforms, then use the standard construction which works on any compiler (Visual C++ included):
//Beginning of the header file
#ifndef __YOUR_HEADER_FILE_H_INCLUDED__
#define __YOUR_HEADER_FILE_H_INCLUDED__//...remaining of your file...
#endif //At the very end of the file
[VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]
-
reza matinnejad wrote:
I avoid making circular includes in this way
this CANNOT happen, as long as you designed your headers correctly. there is a multiple includes exclusion system which tells for the header which it's defined in not to include it more than once... If you're using Visual Studio only, the following is good and prefered for performances. This is MS specific:
//Beginning of the header file
#pragma once//...remaining of your file...
if your sources are portable on pultiple plateforms, then use the standard construction which works on any compiler (Visual C++ included):
//Beginning of the header file
#ifndef __YOUR_HEADER_FILE_H_INCLUDED__
#define __YOUR_HEADER_FILE_H_INCLUDED__//...remaining of your file...
#endif //At the very end of the file
[VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]
Thank you :)
-
Thank you :)
ps, i didn't say it, because it was obvious to me, but you have to be careful that the macros such as "__YOUR_HEADER_FILE_H_INCLUDED__" is unique for each file (if 2 headers define the same macro, redefining identifiers errors may happen)...
[VisualCalc][Binary Guide][CommDialogs] | [Forums Guidelines]