Please Help

Started by
18 comments, last by kaktusas2598 13 years, 11 months ago
#include<iostream> #include<string> using namespace std; class Ogre { protected: int health; int attack; int strength; public: void SpellUse( Spell &hitSpell); }; class Spell { protected: int mana; public: bool SpellHit(int,int); }; int main() { return 0; } bool Spell::SpellHit(int locX, int locY) { if((locX == enemyLocX)&&(locY ==enemyLocY)) return true; else return false; } void Ogre::SpellUse( Spell &hitSpell) { bool hit; hit = SpellHit(300,50); if( hit ) cout<<"Ogre cast a spell on the enemy"<<endl<<endl; } my teacher gave me this code and it fails(which I knew would happen, but he just couldn't use my code. Sorry about this small venting). Please help, these are the errors. error C2061: syntax error : identifier 'Spell' error C2065: 'enemyLocX' : undeclared identifier error C2065: 'enemyLocY' : undeclared identifier error C2511: 'void Ogre::SpellUse(Spell &)' : overloaded member function not found in 'Ogre'
Advertisement
You have to declare enemyLocX and enemyLocY variable first

Deltron Zero and Automator.

how and where?
error C2511: 'void Ogre::SpellUse(Spell &)' : overloaded member function not found in 'Ogre'


this is the error i need fixed now, if i try to fix i get i get another error.
try to put class Spell definition before Ogre definition

Deltron Zero and Automator.

ok i tried that,


#include<iostream>
#include<string>
using namespace std;

class Spell
{
protected:
int mana;
public:
bool SpellHit(int,int);
};

class Ogre
{
protected:
int health;
int attack;
int strength;
public:
void SpellUse();
};

int main()
{

return 0;
}

bool Spell::SpellHit(int locX, int locY)
{
int enemyLocX, enemyLocY;
enemyLocX = rand()%300;
enemyLocY = rand()%50;
if((locX == enemyLocX)&&(locY ==enemyLocY))

return true;
else
return false;
}

void Ogre::SpellUse( Spell &hitSpell)
{
bool hit;
hit = SpellHit(300,50);

if( hit )
cout<<"Ogre cast a spell on the enemy"<<endl<<endl;
}


this is my current code and i still have the previously mentioned error
Quote:Original post by Psych0 P3ngu1n
void SpellUse();

void Ogre::SpellUse( Spell &hitSpell)


Try correct void SpellUse() to void SpellUse(Spell &hitSpell)

Deltron Zero and Automator.

Quote:error C2511: 'void Ogre::SpellUse(Spell &)' : overloaded member function not found in 'Ogre'

Overloaded functions are functions that have the same name but different numbers or types of parameters.

The compiler is looking for the function SpellUse that takes a parameter of type Spell&. In your class definition, SpellUse takes no parameters.

In Ogre class definition:
void SpellUse();

In implementation:
void Ogre::SpellUse(Spell &hitSpell)
"All you have to decide is what to do with the time that is given to you." - Gandalf
error C3861: 'SpellHit': identifier not found

is the new error. It occurs in the SpellUse void where i wrote

hit = SpellHit(300,50);

and thanks for helping with what you've helped with what you have so far. I really appreciate it
try change SpellUse to:
void Ogre::SpellUse( Spell &hitSpell){if(SpellHit(300,50))cout<<"Ogre cast a spell on the enemy"<<endl<<endl;}


I dont think it will corerct error, but it is better way to represent this

Deltron Zero and Automator.

This topic is closed to new replies.

Advertisement