# 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. ## 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?

2. 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...

3. 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

4. Remember that you can only use preprocessor symbols in preprocessor conditionals.

Most likely Player::race is not a preprocessor symbol

5. 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;
};

6. 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;

7. 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.

Popular pages Recent additions