Thank you for the answer! But now a there's a new problem. "undefined reference to" and then it point out the constructors and the function of the class. I have corrected a few other things, the code now is as follow:
monster.h
class monsterType
{
public:
void setStat(std::string nam, int pow, int res, int dif, int sol); //Function for setting the stat to monsters
void printStat(); //Function for printing the stat of a monster
monsterType(std::string nam, int pow, int res, int dif, int sol); //Constructor
monsterType(); //Constructor
private:
std::string nam; //Monsters stat
int pow, res, dif, sol;
};
monster.cpp
#include <string>
#include <iostream>
void monsterType::setStat(std::string name, int str, int cos, int def, int cash) //Function for setting the stat to monsters
{
std::string nam=name;
int pow=str;
int res=cos;
int dif=def;
int sol=cash;
};
void monsterType::printStat() //Function for printing the stat of a monster
{
cout << "nam " << "have " << "pow" << " strenght point/s, " << "res" << " toughness point/s and "
<< "dif" << " defense point/s." << endl;
};
monsterType::monsterType(std::string nam, int pow, int res, int dif, int sol)//Constructor
{
cout << "A new monster appear!"<< endl;
}
monsterType::monsterType()//Constructor
{
cout << "A new monster appear!"<< endl;
}
main.cpp
#include <string>
#include "monster.h"
#include <iostream>
#include <cstdlib>
#include <time.h>
using namespace std;
void setStat(string nam, int pow, int res, int dif, int sol); //monsterType functions
void printStat();
int main()
{
string name; //variables
int str, cos, def, cash;
monsterType enemy; //class object
srand ( time(NULL) ); //Random value
int numberMonster=rand() % 4; //Random value
if(numberMonster>=0 && numberMonster<=4) //Control tower
{
switch(numberMonster) //Possible monsters
{
case 0:
name="Orc";
str=3, cos=3, def=0, cash=2;
enemy.setStat(name, str, cos, def, cash);
enemy.printStat();
break;
case 1:
name="Rat";
str=1, cos=1, def=0, cash=1;
enemy.setStat(name, str, cos, def, cash);
enemy.printStat();
break;
case 2:
name="Soldier";
str=2, cos=2, def=2, cash=2;
enemy.setStat(name, str, cos, def, cash);
enemy.printStat();
break;
case 3:
name="Golem";
str=1, cos=3, def=2, cash=2;
enemy.setStat(name, str, cos, def, cash);
enemy.printStat();
break;
};
}
else cout << "Alert: numberMonster has invalid valor!" << endl;
return 0; //The end
};