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

相關文章
相關標籤/搜索