Hey, y'all. As the thread title suggests, I'm having trouble with capability classes in the C++ language. Basically, I have a capability class and two derived classes from it. All of these are .hpp header files. The capability class has a virtual method which is overridden in both derived classes. The code is fairly short (it's a test program) so I'll some of it here.
CAPABILITY CLASS HEADER FILE:
FIRST DERIVED CLASS HEADER FILE:
SECOND DERIVED CLASS HEADER FILE:
MAIN PROGRAM:
The problem: My compiler keeps highlighting #include "player.hpp" as an error. But I don't know why!!! I'm using the Dev-C++ environment on Windows XP. Can anyone help me? :-(
CAPABILITY CLASS HEADER FILE:
Code:
#include <iostream>
using namespace std;
class Combatants
{
public:
virtual int Attack() const { return -1; } //error
};
FIRST DERIVED CLASS HEADER FILE:
Code:
class Player : public Combatants
{
public:
// Constructor & destructor
Player(int initpAttack, int initpDefend, int initpHP, int initpMP)
{
pAttack = initpAttack;
pDefend = initpDefend;
pHP = initpHP;
pMP = initpMP;
};
~Player() { };
// Player attack method
int Attack( int eHP, int pAttack, int eDefend) const
{
cout << "Player attacks!!!" << endl;
enemyHP = enemyHP ((pAttack * 10)-(eDefend * 5));
return eHP;
}
};
SECOND DERIVED CLASS HEADER FILE:
Code:
class Enemy : public Combatants
{
public:
// Constructor & destructor
Enemy(int initeAttack, int initeDefend, int initeHP, int initeMP)
{
eAttack = initeAttack;
eDefend = initeDefend;
eHP = initeHP;
eMP = initeMP;
};
~Enemy() { };
// Enemy attack method
int Attack(int pHP, int eAttack, int pDefend)
{
cout << "Enemy attacks!" << endl;
pHP = pHP - ((eAttack * 10) - (pDefend * 5));
return pHP;
}
};
MAIN PROGRAM:
Code:
// Include class headers
#include "combatants_capability.hpp"
#include "player.hpp"
#include "enemy.hpp"
// Main program execution
int main()
{
// Delcare pointers to initialize instances of player and enemy
int *pPlayer = new Player(5, 5, 100, 50);
int *pEnemy = new Enemy(5, 5, 100, 50);
// Player attack method call and HP remaining message
pPlayer -> Attack(pHP, eAttack, pDefend);
cout << "Player has " << pHP << " HP remaining.\a" << endl;
// Enemy attack method call
pEnemy -> Attack(eHP, pAttack, eDefend)
cout << "Enemy has " << eHP << " HP remaining.\a" << endl;
// Pause system to allow user to see program results
system("PAUSE");
// Return a 0 to show program executed correctly
return 0;
}
The problem: My compiler keeps highlighting #include "player.hpp" as an error. But I don't know why!!! I'm using the Dev-C++ environment on Windows XP. Can anyone help me? :-(