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
# 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);
# 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