Please Help
#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'
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.
this is the error i need fixed now, if i try to fix i get i get another error.
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
#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)
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)
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
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:
I dont think it will corerct error, but it is better way to represent this
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
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement