Questions tagged [include-guards]

Anything related to C/C++ include guards technique, i.e. a technique employing C-preprocessor conditional compilation features in order to prevent multiple inclusion of header files in C/C++ source files.

Anything related to C/C++ include guards technique, i.e. a technique employing C-preprocessor conditional compilation features in order to prevent multiple inclusion of header files in C/C++ source files.

185 questions
1
vote
2 answers

Include guard style, C++

I have a .h file which contains several class definitions. I'd like to use C++'s include guards in this file; however, I was wondering which way of using the include guards is considered proper/correct? One guard protecting everything #ifndef…
rectangletangle
  • 50,393
  • 94
  • 205
  • 275
0
votes
2 answers

endless include loops

Possible Duplicate: C header file loops Original Question: I always had problems understanding why the following gives errors: something.h #ifndef SOMETHING_H #define SOMETHING_H #include "somethingelse.h" #endif somethingelse.h #ifndef…
xcrypt
  • 3,276
  • 5
  • 39
  • 63
0
votes
1 answer

How a multiple times #included guarded header file will be inside different translation units?

I know that #inclusion is often described as a text copy-pasting preprocessor directive. Now if a header is #include guarded, or #pragma onced, then how'd we describe what is actually happening past the first translation unit to #include said…
0
votes
3 answers

C: Extern variable declaration and include guards

I've had the same problem as described in these two posts (First and Second) regarding declaration of variables in header files. The solution listed works well for me, but nonetheless I have a basic question on the solution: Why would an include…
drdolphin
  • 117
  • 1
  • 6
0
votes
0 answers

How do I best use #include to prevent my multiple definition error?

While implementing three files (tree.h, tree.cpp, and node.h) into an existing project, I've run into "multiple definition of" errors when trying to reference them in my parser.h and parser.cpp files. I am using include guards to prevent multiple…
0
votes
1 answer

Include file includes itself with guards

I have two header files, animation.h and hero.h, here is the code for animation.h: #include #include #include "hero.h" #ifndef ANIMATION #define ANIMATION //Class #endif And for hero.h: #include…
Kerch
  • 25
  • 6
0
votes
1 answer

How to ensure #include doesn't recursively add (only adds unique files once)

I have this file main.h and this file events.h, the file events.h needs to include main.h as the singleton of my Events class requires my singleton of my Main class in order to declare Main as a friend class, so it can access Events private…
0
votes
1 answer

Why do I keep getting Redefinition of Class Error? C++

I keep getting the error: "Redefinition of 'CBSTree'" and "Previous definition is here" on all my functions in my cbstree.cpp code. I'm not sure why. I believe I have the correct include guards and such. Help would be very much appreciated! Thank…
Rachel
  • 9
  • 2
0
votes
2 answers

What is `#ifndef FUNCTIONS_H` in functions.h for?

In a header file functions.h, the first two statements are defining FUNCTIONS_H if not already defined. Can someone explain the reason for this action? #ifndef FUNCTIONS_H #define FUNCTIONS_H void print(); int factorial(int); int multiply(int,…
Learner
  • 85
  • 2
  • 10
0
votes
0 answers

Compiler error 'class_name' is not a type and 'class_name' does not name a type C++

I can't understand why I am getting this errors. When I make the constructor it shows this errors 'bag' is not a type or 'bag' does not name a type and if i delete the constructor, it compiles. #include #include "bag.h" using namespace…
Padelis
  • 41
  • 6
0
votes
1 answer

Double header guards in Visual Studio stl numeric implementation

In the stl implementation that comes along with Visual Studio 12.0 the numeric header looks like this #pragma once #ifndef _NUMERIC_ #define _NUMERIC_ // shortened for the sake of readibility . . . #endif /* _NUMERIC_ */ I know that #pragma…
schorsch312
  • 5,553
  • 5
  • 28
  • 57
0
votes
1 answer

How does MYHEADER_HPP in a header guard relate to the actual file name "MyHeader.hpp"

I'm trying to teach myself C++ and one small detail that I don't understand keeps bugging me. I understand the need for header guards but I don't understand the exact syntax. For example. If I have a header file called MyHeader.hpp and I wanted…
Gene
  • 47
  • 7
0
votes
1 answer

C++ Header Guard Syntax and Header Placement

My question is on proper syntax and usage of header guards. For example if I am including a few common libraries in my C++ code can I make a header guard like what is shown below? Also, from the documentation I could find on header files it was…
0
votes
1 answer

Why is my file executing this header twice even with guards in place while forking in C?

Even with guards in place, my file is still trying to execute the mkdir twice. I tried putting the ifndef in the other c file but it still executes twice p.h #ifndef P_H #define P_H void p1(char* filepath, int m); #endif main.c #include…
0
votes
0 answers

Swig , C++ "include nested too deeply"

I am a beginner at c++ and I'm having this problem with nested include files. The code is too big to put here, but this is the part that I'm getting the error: cvblob.h #ifdef SWIG %module cvblob %{ #include "cvblob.h" %} #endif #ifndef…
Hadi GhahremanNezhad
  • 2,377
  • 5
  • 29
  • 58