header file confusion

This is a discussion on header file confusion within the C++ Programming forums, part of the General Programming Boards category; Ok, since my source is big, I want to divide my project into header files like so: Code: - main.cpp ...

  1. #1
    Registered User abrege's Avatar
    Join Date
    Nov 2002
    Posts
    369

    header file confusion

    Ok, since my source is big, I want to divide my project into header files like so:

    Code:
    - main.cpp
         + player.h
         + monster.h
         + shop.h
    But theres things in player.h that I need in shop.h and monster.h, and when I connect everything to everything all I get is a bunch of errors. Can anyone instruct me on how to properly work header files??
    I am against the teaching of evolution in schools. I am also against widespread
    literacy and the refrigeration of food.

  2. #2
    Just because ygfperson's Avatar
    Join Date
    Jan 2002
    Posts
    2,493
    put only declarations and prototypes in header files. if you're already doing that, try this:

    Code:
    #ifndef PLAYER_H
    #define PLAYER_H
    
    /* rest of player.h file goes here */
    
    #endif
    do this for all 3 header files. Then, you don't have to worry about things screwing up just because you have included a header file twice.

    More specifically, the first time any of these header files are included, the #define command is activated. If it's included for the second time or any time after that, #ifndef detects that and just ignores the repeat header file.

  3. #3
    Registered User abrege's Avatar
    Join Date
    Nov 2002
    Posts
    369
    thanks, ill try that!
    I am against the teaching of evolution in schools. I am also against widespread
    literacy and the refrigeration of food.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. File transfer- the file sometimes not full transferred
    By shu_fei86 in forum C# Programming
    Replies: 13
    Last Post: 03-13-2009, 01:44 PM
  2. Formatting the contents of a text file
    By dagorsul in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2008, 01:36 PM
  3. Need help understanding Header Files
    By Kaidao in forum C++ Programming
    Replies: 11
    Last Post: 03-25-2008, 11:02 AM
  4. Unknown Memory Leak in Init() Function
    By CodeHacker in forum Windows Programming
    Replies: 3
    Last Post: 07-09-2004, 10:54 AM
  5. Replies: 6
    Last Post: 04-02-2002, 05:46 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21