#include <iostream>
class Battle
{
public:
void mainbattle(Hero, Monster);
};
battle.cpp
1 2 3 4 5 6 7
#include "Battle.h"
void Battle::mainbattle(Hero, Monster)
{
std::cout << "you are fighting a monster";
//battle takes place here
}
its giving me an error that Hero and monster have not been declared, or declared in this scope,in battle.h.
*Hero and monster are nearly identical class that contain health for each, and then contains its own header file, the issue is not contained in either.
When you try to compile battle.cpp, the preprocessor turns it into this
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
#include <iostream>
// BEGIN THE PASTE FROM battle.h BY THE PREPROCESSOR
class Battle
{
public:
void mainbattle(Hero, Monster);
};
// END THE PASTE FROM battle.h BY THE PREPROCESSOR
void Battle::mainbattle(Hero, Monster)
{
std::cout << "you are fighting a monster";
//battle takes place here
}
See how your code tries to use the classes Hero and Monster? Where in battle.cpp (or the pasted text from battle.h)are they declared? Nowhere, that's where! :)
You haven't mentioned where in the file error occurs.
Also, in battle.h, isn't it supposed to include MainGame.h or something to forward declare the classes Hero and Monster ???