ifndef 和 #pragma once 区别

#ifndef   是为了防止一个源文件屡次include同一个头文件。
No, it's not the same.ide

If your compiler supports "#pragma once",
It will ignore the rest of the header file when it finishes reading this line.
But if you use "#ifndef xxx", "#define xxx", "...", "#endif",
the compiler will go on parsing this file because it thinks that
  there may be some more lines of code after "#endif",
it dare not to drop the rest of the file.this

As you see,
if the compiler supports "#pragma once",
using "#pragma once" will accelerate the compiling process.
So people usually write header file like this:rest

#ifndef XXX
#define XXXcode

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VERit

...
...class

#endif // XXX
 file

相关文章
相关标签/搜索