Jump to content
  • Advertisement
Sign in to follow this  
Psych0 P3ngu1n

Please Help

This topic is 3122 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

#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'

Share this post


Link to post
Share on other sites
Advertisement
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
Quote:
Original post by Psych0 P3ngu1n
void SpellUse();

void Ogre::SpellUse( Spell &hitSpell)


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

Share this post


Link to post
Share on other sites
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)

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!