Common methods to prevent header files from being included multiple times in C ++ include:
1) Use the # ifndef... # define... # endif macro
# Ifndef _ myheader_h __
# DEFINE _ myheader_h __
// Here is my class...
# Endif
2) use # pragma once
# Pragma once
// Here is my class...
We recommend that you use # pragma once for the following reasons:
1) the code is concise and easy to maintain. # Pragma once is much shorter than # ifndef... and avoids _ myheader_h _ redefinition or # endif inclusion range error.
2) Fast compilation. If # ifndef is used, the compiler reads the # include file and parses the code each time. The # pragma once compiler does not open files repeatedly, which greatly improves the efficiency.
The above two points are particularly outstanding in large-scale C ++ projects.
Note:# Pragma once is not an international standard, but a function of Microsoft C ++. However, most mainstream C ++ compilers have also implemented this function.
> Original article copyright belongs to the author, reprint please indicate the source and author information (http://blog.csdn.net/WinGeek/), thank you. <