I created a class in a separate .h and .cpp file with the idea of having an array of 3 monsters with each monster having different stats( name; health; damage). The problem is that the constructor should change the properties but when I try to call them in the main file only the 3rd monster's properties are changed.
main.cpp
#include <string>
#include <iostream>
#include <Windows.h>
#include <stdio.h>
using namespace std;
#include "Player.h"
#include "Monsters.h"
#include "MonsterCluster.h"
int main()
{
Player player;
Monsters monster;
MonsterCluster enemies;
enemies = MonsterCluster(0, "Goblin", 20, 5);
enemies = MonsterCluster(1, "Wraith", 50, 10);
enemies = MonsterCluster(2, "Legionare", 80, rand() % 60+20);
cout << enemies.monsterList[2].name << endl;
}
MonsterCluster.h
#pragma once
#include "Monsters.h"
class MonsterCluster :
public Monsters
{
public:
Monsters monsterList[3];
MonsterCluster();
MonsterCluster(int _monsterIndex, string _name, int _health, int _damage);
}
MonsterCluster.cpp
MonsterCluster::MonsterCluster()
{
/*name = "";
health = 2;
damage = 3;*/
}
MonsterCluster::MonsterCluster(int _monsterIndex, string _name, int _health, int _damage)
{
monsterList[_monsterIndex].name = _name;
monsterList[_monsterIndex].health = _health;
monsterList[_monsterIndex].damage = _damage;
}