some questions regarding header guards
1. Which is the best way to do it?
a.
b.
Code:
#ifndef THISFILESNAME_H
#define THISFILESNAME_H
//code in the file
#endif
?
Or, should I use both of them? Or, Is there a better way than these?
I currently use #pragma once (I'm using visual c++).
Re: some questions regarding header guards
The first method is not standard and will not work with all compilers; furthermore, when a pre-processor encounters a #pragma directive it does not understand, it is (usually) silently ignored, so you won't even know it has done nothing.
The second method is standard and will work.
Re: some questions regarding header guards
pragma once is not standard C++. It was developped by microsoft as an easy alternative to include guards. But, to be honest, if you are having trouble using include guards, its time to move on to another job.
Some people will tell you that pragma once can speed up compilation. May have been true 10 years ago.
I'd just stick to include guards. Everyone knows what they are, and how to use them.
EDIT: I'm not saying its wrong to use pragma once: It works perfectly well, and does it well. It's just I don't see the point of using something non-standard when you have a perfectly good standard way of doing it.