Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

Homework Help Please

Ok i have an assignment to make a class in a header file, i have a very simple program that i cant figure out why it won work it keeps giving me this error code:

expected primary-expression before "int"

main:

#include <iostream>
#include "Hero.h"

using namespace std;

int main ()
{
int Weapon = 4;

Hero Atk;

Atk.Attack (int weapon);

return 0;
}

Header file:

#ifndef _THING_H
#define _THING_H

#include <iostream.h>

class Hero{
public:
Hero();
void Attack (int Weapon);
private:

};

Hero::Hero ()
{
}

void Hero::Attack (int Weapon)
{
cout << "You deal " << Weapon << "damage" << endl;
system("PAUSE");
}

#endif

is this because i am trying to do implimentaion in a header file or am i just missing something entirely? Thanks for your help
[1017 byte] By [cameron_tibbits] at [2007-11-11 10:24:50]
# 1 Re: Homework Help Please
1. add this include for 'system()' function that you have used : #include <stdlib.h>

2. In this statement : Atk.Attack (int weapon); , the keyword 'int' is not expected here and you can just pass the name of the variable to the function, not its type! -> Atk.Attack (weapon);
Mohammad Rast at 2007-11-11 20:58:53 >
# 2 Re: Homework Help Please
Hmmm... i changed the code and now its telling me that Attack isn't a class type in hero.h

Error:
request for member `Attack' in `Atk', which is of non-class type `Hero ()()'

my code looks like this now:

main:

#include <iostream>
#include "Hero.h"

using namespace std;

int main ()
{
int Weapon = 4;

Hero Atk ();

Atk.Attack (Weapon);

return 0;
}

Hero.h:

#ifndef _THING_H
#define _THING_H

#include <iostream.h>
#include <stdlib.h>

class Hero{
public:
Hero();
void Attack (int Weapon);
private:

};

Hero::Hero ()
{
}

void Hero::Attack (int Weapon)
{
cout << "You deal " << Weapon << "damage" << endl;
system("PAUSE");
}

#endif

thanks for your time
cameron_tibbits at 2007-11-11 20:59:55 >
# 3 Re: Homework Help Please
Peace
instead :
Hero Atk ();
you just write :
Hero Atk ;

coze Atk is a class(hero) no need to put () !!!
peace_comp at 2007-11-11 21:00:59 >
# 4 Re: Homework Help Please
Thanks a lot guys that worked
cameron_tibbits at 2007-11-11 21:01:53 >