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:
//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
cout<<"Choose your class (1=Mage, 2=Knight): ";
if (classchoice == 1)
character = new Mage;
elseif (classchoice == 2)
character = new Knight;
while ( character->death() != true )
for(int i=0; i<21; i++)
cout<<"\nA wild Enemy appears" <<endl;
while (army.at(i)->death() != true)
cout<<"choose your action: "<<endl;
cout<<"Attack Enemy = 1\nHeal = 2\nSpecial attack = 3"<<endl;
if (action == 1)
cout<<"You attacked Enemy"<<endl;
elseif (action == 2)
cout<<"Tsengel attacked you"<<endl;
} //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
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