Thread: Prototyping a class

  1. #1

    Prototyping a class

    It is possible to prototype a class? I have my player class in a header file, and my creatures class on another. In a few of the methods, they interact. If i #include them in both, the compiler complains about redefinitions. Can i prototype the class like i prototype methods so i can use it?
    Compilers:
    GCC on Red Hat 8.1 (Primary)
    GCC on Mac OS X 10.2.4 (Secondary)

    Others:
    MinGW on XP

  2. #2
    Has a Masters in B.S.
    Join Date
    Aug 2001
    Posts
    2,263
    are you using "inclusion guards"?
    ADVISORY: This users posts are rated CP-MA, for Mature Audiences only.

  3. #3

    Inclusion Guards

    so would i do something like this in each header file?


    Code:
    //players.h
    
    #ifndef "creatures.h"
    #define "creatures.h"
    #include "creatures.h"
    #endif
    
    //creatures.h
    
    #ifndef "players.h"
    #define "players.h"
    #include "players.h"
    #endif

  4. #4
    Has a Masters in B.S.
    Join Date
    Aug 2001
    Posts
    2,263
    more like

    Code:
    //creatures.h
    
    #ifndef _CREATURES_H_FILE_INCLUDED
    #define _CREATURES_H_FILE_INCLUDED
    
    // creatures.h code goese here
    
    #endif
    
    //players.h
    
    #ifndef _PLAYERS_H_FILE_INCLUDED
    #define _PLAYERS_H_FILE_INCLUDED
    
    // players.h code goes here
    
    #endif
    ::edit:: try and make the defines something that won't be used and hasn't already been used
    ADVISORY: This users posts are rated CP-MA, for Mature Audiences only.

  5. #5
    Aaaah. I think i see the light...

  6. #6
    Registered User rmullen3's Avatar
    Join Date
    Nov 2001
    Posts
    330
    Yeeep. Preprocessor directives are the spiffy.

  7. #7
    Any reason you cant use '#pragma once' in the headers?
    "There's always another way"
    -lightatdawn (lightatdawn.cprogramming.com)

  8. #8
    Registered User moi's Avatar
    Join Date
    Jul 2002
    Posts
    946
    Originally posted by lightatdawn
    Any reason you cant use '#pragma once' in the headers?
    non standard
    hello, internet!

  9. #9
    Has a Masters in B.S.
    Join Date
    Aug 2001
    Posts
    2,263
    + it has never worked for me once.
    ADVISORY: This users posts are rated CP-MA, for Mature Audiences only.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Class design problem
    By h3ro in forum C++ Programming
    Replies: 10
    Last Post: 12-19-2008, 09:10 AM
  2. Specializing class
    By Elysia in forum C++ Programming
    Replies: 6
    Last Post: 09-28-2008, 04:30 AM
  3. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 02:39 PM
  4. Creating a database
    By Shamino in forum Game Programming
    Replies: 19
    Last Post: 06-10-2007, 01:09 PM