Alright, I got bored and took a short break from Win32 programming and I set out to make an RPG battle system type program in console, but I'm having some problems. I have 2 classes which I'm having trouble with right now, the Player class and the Character class. The charater class will hold the player's hp and the enemie's hp for easy life deduction. They all have seperate files because I like things like that. Here's my code:
character.h
#ifndef CHARACTER_H
#define CHARACTER_H
class Character
{
public:
Character(){}
protected:
int p_hp;
};
#endif
player.h
#ifndef PLAYER_H
#define PLAYER_H
#include <iostream>
#include <time.h>
#include "enemy.h"
#include "character.h"
class Player : public Character
{
public:
Player(); // Default Constructor
private:
char * Pname; // The players name
int Killed; // How many enemies a specific player has killed
};
#endif
player.cpp
#include "player.h"
Player::Player():
Killed(0),
Character::p_hp(20)
{
char * name = new char;
std::cout << "What's would you like to name your character? \t";
std::cin >> name;
Pname = name;
std::cout << "You will from now on be known as " << name << "!\n";
std::cout << name << " has killed " << Killed << " enemies!\n";
}
I have other files but right now these are the one's I'm concerned with. When I try to compile what I have, I get an error in "player.cpp" saying this: player.cpp(6) : error C2614: 'Player' : illegal member initialization: 'p_hp' is not a base or member
Line 6 in that is where I initialize the needed variables for the created player, the line is this:
Character:: P_hp(20)
What am I doing wrong? (I had to put a space between the : and the P because of the smileys)
R.I.P. Mark Osback
Solo Pa Mi Gente
VG-Force
[edited by - Ekim_Gram on November 30, 2003 3:26:20 PM]
[edited by - Ekim_Gram on November 30, 2003 3:28:26 PM]