I am using #pragma once
in my .cpp
s and .hpp
s and because of that I get a warning for each file that uses it. I have not found any opt
Indeed the #ifndef
guard can always be used, but just to remove the warning while compiling the source which uses #pragma once
I would recommend to use the -w
option while compiling.
e.g. gcc -w -o <output file> <input file(s)>
The common approach is to place the guard in the .h file only:
#ifndef MYFILE_H
#define MYFILE_H
// all your myfile.hpp here
#endif
or
#pragma once
// all your myfile.hpp here
The rest of files (other .cpp) should do nothing regarding the guards. You should not get warnings by doing this.