Thread: inclusion guard help

  1. #1
    Registered User
    Join Date
    Jul 2006
    Posts
    5

    inclusion guard help

    Hello I am trying to make a game and i disided to break it up into several files using headers to hold all the variables and that kind of stuff but i need to include the headers into all of the CPP files so i know i need to use inclusion guards but they just dont seem to work at all. its like the preprocessor just skips over the #ifndef command can some one help me with this?

    i have a book that says to use this set up:

    Code:
    #ifndef Lybraries_h           // the book says that the file name does need to be capital
    #define Lybraries_h
    
    // everthing here
    
    #endif
    Last edited by romerboy55; 09-01-2006 at 11:44 PM.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    You did pick a different name for each file right?

    If my header file is say myfuncs.h, then it's include guard would be
    #ifndef MYFUNCS_H_INCLUDED

    If you pick the same #define name for different files, then yes the latter ones will be skipped.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Jul 2006
    Posts
    5
    I dont think i compleatly understand do you think you could give an example.

    ps.i only have one file that i am including into all the other files, I made it with all the variables in it

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. preprocessor file inclusion?
    By dwaugh in forum C Programming
    Replies: 4
    Last Post: 08-22-2008, 09:01 AM
  2. Source file inclusion
    By sh3rpa in forum C++ Programming
    Replies: 7
    Last Post: 10-02-2007, 11:10 AM
  3. MSVC #pragma once and inclusion guards
    By cboard_member in forum Tech Board
    Replies: 4
    Last Post: 12-23-2006, 08:17 AM
  4. inclusion guards
    By Iamregistered in forum C++ Programming
    Replies: 1
    Last Post: 02-20-2003, 07:46 AM
  5. Inclusion of header class
    By Unregistered in forum C++ Programming
    Replies: 0
    Last Post: 12-08-2001, 03:33 PM