Preprocessor Directives Problem

This is a discussion on Preprocessor Directives Problem within the C++ Programming forums, part of the General Programming Boards category; Hi, I got a source code with these preprocessor directives: Code: #if Player::race = 0 #include "warrior.h" #elif Player::race = ...

  1. #1
    the Wizard
    Join Date
    Aug 2004
    Posts
    109

    Preprocessor Directives Problem

    Hi,

    I got a source code with these preprocessor directives:
    Code:
    #if Player::race = 0
    #include "warrior.h"
    #elif Player::race = 1
    #include "conjurer.h"
    #elif Player::race = 2
    #include "wizard.h"
    #endif
    And I have a meaning that the warnings I get is somehow the reason for my program getting some errors about some classes in some different files than my main file.
    Anyway, my warnings for the code is:
    Code:
    d:\c++\text_based_game\race.h(9) : warning C4067: unexpected tokens following preprocessor directive - expected a newline
    d:\c++\text_based_game\race.h(9) : warning C4067: unexpected tokens following preprocessor directive - expected a newline
    d:\c++\text_based_game\race.h(11) : warning C4067: unexpected tokens following preprocessor directive - expected a newline
    d:\c++\text_based_game\race.h(11) : warning C4067: unexpected tokens following preprocessor directive - expected a newline
    d:\c++\text_based_game\race.h(13) : warning C4067: unexpected tokens following preprocessor directive - expected a newline
    d:\c++\text_based_game\race.h(13) : warning C4067: unexpected tokens following preprocessor directive - expected a newline
    Can somebody give me a hand with my problem?
    Thx in advance.
    -//Marc Poulsen -//MipZhaP

    He sat down, he programmed, he got an error...

  2. #2
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    All I can say is that looks like realy bad programming... (at least in C++ terms). do you happen to have the rest of the code? the problems I get with only that is that you can't use '::' or '=' in preprocessor directives. the following compiles just fine though:
    Code:
    #if race == 0
    #include "warrior.h"
    #elif race == 1
    #include "conjurer.h"
    #elif race == 2
    #include "wizard.h"
    #endif
    of course, I still get errors about those files not existing, but that can't be helped. If you #include <iostream> instead, you only get errors about the lack of a main routine.

    it looks like they were attempting some kind of bizzare form of inheritance or something...
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  3. #3
    the Wizard
    Join Date
    Aug 2004
    Posts
    109
    Hmm...
    The int race, is a member of a Class(Player), so I can't use that it works without.
    But thx, for giving it a great try

    Well, I've spotted a problem that might solve it. Actually your post gave me the reminder, so thx for posting :P
    -//Marc Poulsen -//MipZhaP

    He sat down, he programmed, he got an error...

  4. #4
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    Remember that you can only use preprocessor symbols in preprocessor conditionals.

    Most likely Player::race is not a preprocessor symbol

  5. #5
    the Wizard
    Join Date
    Aug 2004
    Posts
    109
    Well this is my class player:
    There also is a problem with the string name, my compiler complains about the lack of a ";" before the string name line.

    Code:
    class player
    {
    	public:
    		player(int hp, int mp, int lvl, int att, int def);
    		~player();
    		int getHP() {return HP;};
    		int getMP() {return MP;};
    		int getLvl() {return Lvl;};
    		int getAtt() {return Att;};
    		int getDef() {return Def;};
    		void LvlUP();
    		string name;
    
    	protected:
    		int race;
    		int HP;
    		int MP;
    		int Lvl;
    		int Att;
    		int Def;
    };
    -//Marc Poulsen -//MipZhaP

    He sat down, he programmed, he got an error...

  6. #6
    Registered User major_small's Avatar
    Join Date
    May 2003
    Posts
    2,787
    Quote Originally Posted by MipZhaP
    Well this is my class player:
    There also is a problem with the string name, my compiler complains about the lack of a ";" before the string name line.
    are you sure you properly defined the string class? by that I mean you need the following lines before the class:
    Code:
    #include <string>
    
    using namespace std;
    //or
    using std::string;
    Join is in our Unofficial Cprog IRC channel
    Server: irc.phoenixradio.org
    Channel: #Tech


    Team Cprog Folding@Home: Team #43476
    Download it Here
    Detailed Stats Here
    More Detailed Stats
    52 Members so far, are YOU a member?
    Current team score: 1223226 (ranked 374 of 45152)

    The CBoard team is doing better than 99.16% of the other teams
    Top 5 Members: Xterria(518175), pianorain(118517), Bennet(64957), JaWiB(55610), alphaoide(44374)

    Last Updated on: Wed, 30 Aug, 2006 @ 2:30 PM EDT

  7. #7
    the Wizard
    Join Date
    Aug 2004
    Posts
    109
    No, that's what I forgot. I'm new to classes, so they are pretty bad written.
    But I think I've found the right road again, thx.
    -//Marc Poulsen -//MipZhaP

    He sat down, he programmed, he got an error...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help understanding a problem
    By dnguyen1022 in forum C++ Programming
    Replies: 2
    Last Post: 04-29-2009, 05:21 PM
  2. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 11:22 AM
  3. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 09:38 AM
  4. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 03:51 PM
  5. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 07:54 PM

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