Sign in to follow this  
Psych0 P3ngu1n

Please Help

Recommended Posts

Psych0 P3ngu1n    100
#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
Psych0 P3ngu1n    100
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
Psych0 P3ngu1n    100
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
Alatar    303
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
Psych0 P3ngu1n    100
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
kaktusas2598    953
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
Psych0 P3ngu1n    100
alright, I've tried almost everything given to me on this site and its moved me along. Ive also tried things said to me by friends. Its still not working. Im going to take a break clear my head and find out how to make SpellUse() work.

error C3861: 'SpellHit': identifier not found

Is still the error. If you figure out please let me know. Thanks for all your help, I will be back in an hour or so.

Share this post


Link to post
Share on other sites
Alatar    303
SpellHit is a member of Spell, not Ogre, so you need to use an object of Spell to call it. That's why there's a Spell parameter for Ogres SpellUse function.

bool hit = hitSpell.SpellHit(300, 50);

Share this post


Link to post
Share on other sites
Psych0 P3ngu1n    100
ok so the hitspell.spellhit worked.

int main()
{
Ogre Ricky;
Ricky.SpellUse();
return 0;
}


what do i need to put the () marks as an arguement. my teacher says i need a spell object in there. What does he mean?

Share this post


Link to post
Share on other sites
Psych0 P3ngu1n    100
Ya lol, I'm glad I found this site. But at the same time I feel like a ginormous idiot for asking stupid questions. Specially looking at some of the other threads in the beginner forums.

Also whats sad is I take notes, I read the books he has had us look at. And I'm two terms into programming. Five terms into my school. Ugh I hate this teacher.

Share this post


Link to post
Share on other sites
Psych0 P3ngu1n    100
Ya lol, I'm glad I found this site. But at the same time I feel like a ginormous idiot for asking stupid questions. Specially looking at some of the other threads in the beginner forums.

Also whats sad is I take notes, I read the books he has had us look at. And I'm two terms into programming. Five terms into my school. Ugh I hate this teacher.

Share this post


Link to post
Share on other sites
rip-off    10979
You need to understand classes versus instances. You have a class for Ogres, and a class for spells. But when you go to use them, you have to specify which Ogre and which Spell you want to use.

So when the Ogre is going to use a spell, your function is designed that you will pass the spell to use as an argument. If you don't use this, your Ogre class would not be able to use arbitrary spells.

Your main() function should create at least one Ogre, and at least one Spell:

int main()
{
Spell fireball;
Spell thunderbolt;
Spell freezeray;

Ogre bill;
Ogre ted;

bill.SpellUse(fireball);
ted.SpellUse(freezeray);

// Or use random spell!
Spell spells[] = { fireball, thunderbolt, freezeray };
Spell &spell = speels[rand() % 3];
bill.SpellUse(spell);
}

Share this post


Link to post
Share on other sites
Psych0 P3ngu1n    100
Rip-Off.....THANK YOU! that worked and I understood it. You don't know how relieved I just got know that i see it working.

Alatar and kaktusas2598 thank you for all the help you gave me. You helped out a lot. Thank you once again for making me get rid of my problems with my code.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this