Function call does no accept argument...

Hey everybody.
I was trying to look up solution for this for quite a while already but found nothing. I am writing a simple console based turn based RPG game for my class project. I was trying to have a member function attack() in class of the player character, which affects the component called health of the class Enemy. both this classes are inherited from the base class Unit. I tried to pass the object of type enemy as an argument to the function attack, but the function call gives me Error: too many arguments in function call. Here's the code for classes:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <string>
using namespace std;



class Unit
{
protected: int power, intellect; 
		   string name;

public: 
	int health;
	Unit() { };

		virtual void attack() {  }
		virtual void heal() { health += intellect;	}
		virtual void spec() { }
		virtual void showstats() { cout<<"HP: "<<health<"   ";  }
		bool death() { if (health<=0) {return true;} 
						else return false;
		 }

};

class Player: public Unit    
{


protected: int race; 
public: Player(){cout<<"please choose race (1 = Human, 2 = Dwarf, 3 = Elf)"<<endl;
					cin>>race;};


	void attack() { } ;  //attack based on power
	void heal()   { } ; //heal
	void spec() {};     //special attack 
	
	
};

class Enemy: public Unit
{
protected: string type;

public:
	
	Enemy() 
		{ srand(time(NULL));
			health = 15 + rand()%5;
			power = 8 + rand()%5;			
			intellect = 15 + rand()%5;
			type = "Regular";
			
		}

	void attack() { health -= power/2 + rand()%4; }
	void showstats() { if (health<0) {health=0;}; cout<<"HP: "<<health<<"   "<<endl<<endl; }
	
	
};

class Boss: public Enemy
{
public:
	Boss() 	{ srand(time(NULL));
			health = 150 + rand()%15;
			power = 30 + rand()%20;			
			intellect = 40 + rand()%15;
			type = "Boss";
			
			}						
	
	void attack(Unit) {  health -= power/2.5; }
	void showstats() { if (health<0) {health=0;}; cout<<"HP: "<<health<"   "; }
};


class Mage: public Player
{ 
protected: int mana;

public: Mage(){if (race == 1){ health = 80;  intellect = 50; power = 8; mana = intellect*2;}    //human
		else if (race == 2) { health = 90; intellect = 45; power = 9; mana = intellect*2;}		//dwarf
		else if (race == 3) { health = 70; intellect = 60; power = 7;  mana = intellect*2;}		//elf
				 cout<<"Mage Created"<<endl;};

		 void attack(Unit * x) { health -= (power+intellect)/5;} 
		 void heal() { health += intellect/2; mana -= 12;    }
		 void spec(Unit) { health -= intellect-rand()%8; mana -= 20; }
		 void showstats() { if (health<0) {health=0;}; cout<<"You:  HP: "<<health<<"   "; cout<<"MP: "<<mana<<endl; }


and the main function

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include <iostream>
#include "Unit.h"
#include <vector>
using namespace std;


void main()

{
	//vector of enemies
	vector <Enemy *> army;
	for (int i=0; i<20; i++)
	{	
		
		army.push_back( new Enemy );

	}
		army.push_back( new Boss );
	    
		int action;     //used in the actions loop
		Player *character;
		int classchoice;
		cout<<"Choose your class (1=Mage, 2=Knight): ";
		cin>>classchoice;
		if (classchoice == 1)
			character = new Mage;
		else if (classchoice == 2)
			character = new Knight;
		else cout<<"WRONG"<<endl;



		while ( character->death() != true )
		{
			character->showstats();
			
			for(int i=0; i<21; i++)
			{
				
				cout<<"\nA wild Enemy appears" <<endl;
				
				while (army.at(i)->death() != true)
				{army.at(i)->showstats();
				cout<<"choose your action: "<<endl;
				cout<<"Attack Enemy = 1\nHeal = 2\nSpecial attack = 3"<<endl;
					
					cin>>action;
					if (action == 1)
					{ 
					 cout<<"You attacked Enemy"<<endl;
					 character->attack(&army.at(i));
					 army.at(i)->attack();
					  character->showstats();
					  
					
					}

					else if (action == 2)
						{character->heal();
					character->showstats();
					  
					}

					cout<<"Tsengel attacked you"<<endl;
					character->attack();
					character->showstats();
				} //end life check while





			}  //end of for loop

		} //end while loop
	
} //end of main function 


All the help is appreciated. Thanks in advance.
P.S Sorry if thread with similar topic already exists, I just could not find any.
P.P.S and sorry if my code is not very readable, I'm working on that :D
Cheers
Last edited on
Line 21 and 77 on Unit.h you are missing a <
Last edited on
Thanks for pointing that out, but I don't think that has to do something with my problem :(
lol I know
The Boss::attack function is the only one that takes an argument - hence the error.

Btw if you have compile errors, then post them in full. It is easier for us, so we don't have to do our own "in brain compiling"

main is always int main not void main. The fact that your compiler allows void main means it is REALLY OLD like Borland Turbo C++ say, if so you would be much better off getting a modern compiler like gcc or clang. clang has really nice messages.

Line 76 divides health (an int) by 2.5 (a double), with the answer a double being truncated to int again - is this what you want?

The usual convention is to split your code into header & implementation files. The class declaration go into a .h file, while the definition of the functions go into a .cpp file

Hope all goes well.

I figured out my mistake. I didn't put argument in Player::attack.
Thanks a lot for help.
Topic archived. No new replies allowed.