header guards and #pragma once

May 8, 2019 at 11:31pm
hi,

Is it necessary to use both header guards and #pragma once sometimes? I ask because I now have a class that explodes without #pragma once even though I have had guards in place.
edit: I just seems weird to me

thanks
Last edited on May 8, 2019 at 11:34pm
May 9, 2019 at 12:19am
Can you paste the header file giving problems?

#pragma once is non-standard, but supported by mainstream compilers (gcc, clang, msvc). Using both can't hurt.
Last edited on May 9, 2019 at 12:23am
May 9, 2019 at 12:34am
1
2
3
4
5
6
7
8
9
10
11
#ifndef SQAUD_H
#define SQUAD_H
#pragma once
#include "Person.h"
#include <array>
#include "Movement.h"
#include "Toolbox.h"
#include "Direction.h"
class Squad
{};
#endif  


edit: I don't think the contents of the class would matter here so I omitted them
Last edited on May 9, 2019 at 12:36am
May 9, 2019 at 12:53am
Look very, very closely at the first two lines :)
May 9, 2019 at 1:24am
Honestly I would have never spotted that on my own. Thanks!
May 9, 2019 at 1:36am
You've also discovered why #pragma once was "invented"

Topic archived. No new replies allowed.