Prototyping a class

This is a discussion on Prototyping a class within the Game Programming forums, part of the General Programming Boards category; It is possible to prototype a class? I have my player class in a header file, and my creatures class ...

  1. #1
    Rebooted Inquirer's Avatar
    Join Date
    Apr 2002
    Posts
    281

    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,267
    are you using "inclusion guards"?
    ADVISORY: This users posts are rated CP-MA, for Mature Audiences only.

  3. #3
    Rebooted Inquirer's Avatar
    Join Date
    Apr 2002
    Posts
    281

    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,267
    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
    Rebooted Inquirer's Avatar
    Join Date
    Apr 2002
    Posts
    281
    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
    Peace
    Join Date
    Aug 2001
    Posts
    1,510
    Any reason you cant use '#pragma once' in the headers?
    "There's always another way"
    -lightatdawn (lightatdawn.cprogramming.com)

  8. #8
    moi
    moi is offline
    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,267
    + 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, 05:30 AM
  3. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 03:39 PM
  4. Creating a database
    By Shamino in forum Game Programming
    Replies: 19
    Last Post: 06-10-2007, 02:09 PM
  5. Abstract class problem
    By VanJay011379 in forum C++ Programming
    Replies: 9
    Last Post: 07-31-2002, 02:30 PM

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