karunesh wrote:
Dear Erik ,
Thanks for a beautiful Explation .
as i know in inclusion gard we use
#ifndef _SOME_
/* Header file body */
#endif
In MSVC, the same code could be written as:
#pragma once
/* Header file body */
Note that your way is portable. But the one nice thing about the
pragma approach is that it avoids the error when you cut and paste your
code to another file, and forget to rename _SOME_, then your header
files clash. (I.e., you can just put that one line, and don't have to
edit it for each header file.)
The other time I tend to use pragmas is to turn certain warnings off.
MSVC has one particularly annoying one if you do something like this:
std::map<std::string, int>
where when it instantiates templates, it winds up creating mangled
names that are really long and then gives you a warning that the names
are very long. I tend to turn that one off (although now I favor
turning it off globally across the whole project, rather than using
#pragma on a file-by-file basis). As was mentioned before,
implementation-specific stuff.
Michael