Estoy intentando que una función devuelva un string aleatorio de un array de strings pero se ve que no estoy pasándole los parámetros a la función de forma correcta. El problema está en el main.cpp
Este es mi código:
Player.h#ifndef PLAYER_H
#define PLAYER_H
#include <string>
class Player{
public:
Player(std::string name, int health, int damage);
void setName(std::string name);
std::string getName() const;
void setHealth(int health);
int getHealth() const;
void setDamage(int damage);
int getDamage() const;
private:
std::string name;
int health;
int damage;
};
#endif /* JUGADOR_H */
Player.cpp
#include "Player.h"
Player::Player(std::string name, int health, int damage){
setName("default");
setHealth(100);
setDamage(30);
}
void Player::setName(std::string name)
{
this->name = name;
}
void Player::setHealth(int health){
health = 100;
}
void Player::setDamage(int damage){
damage = 30;
}
std::string Player::getName() const{
return name;
}
int Player::getHealth() const{
return health;
}
int Player::getDamage() const{
return damage;
}
main.cpp
#include <cstdlib>
#include "Player.h"
#include "Monster.h"
#include <iostream>
#include <string>
int main(int argc, char** argv) {
std::string name;
std::cout <<"Hello! Write your name "<<std::endl;
getline(std::cin, name);
Player player(name, 100, 30);
std::cout <<"Welcome "<<player.getName();
std::string monsters[3] = {"Orc", "Troll", "Undead"};
srand(time(NULL));
int ranM = (rand() % 3); //random monster
Monster monster(std::string monsters[ranM], 50,15);
std::cout <<"Suddenly you encounter a"<<monster.getName();
}