Made a monster array for a text based game with a class constructor C++ 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 &lt;string&gt;
#include &lt;iostream&gt;
#include &lt;Windows.h&gt;
#include &lt;stdio.h&gt;
using namespace std;



#include &quot;Player.h&quot;
#include &quot;Monsters.h&quot;
#include &quot;MonsterCluster.h&quot;

int main()
{

    Player player;
    Monsters monster;
    MonsterCluster enemies;

    enemies = MonsterCluster(0, &quot;Goblin&quot;, 20, 5);
    enemies = MonsterCluster(1, &quot;Wraith&quot;, 50, 10);
    enemies = MonsterCluster(2, &quot;Legionare&quot;, 80, rand() % 60+20);

    cout &lt;&lt; enemies.monsterList[2].name &lt;&lt; endl;
}

MonsterCluster.h
#pragma once
#include &quot;Monsters.h&quot;

class MonsterCluster :
    public Monsters
{
public:
    Monsters monsterList[3];



    MonsterCluster();
    MonsterCluster(int _monsterIndex, string _name, int _health, int _damage);
   
    
}

MonsterCluster.cpp
MonsterCluster::MonsterCluster()
{
    /*name = &quot;&quot;;
    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;
}
Don't write using namespace std;.
You are passing std::string by value, which copies the string.  Generally you want to pass as const std::string&amp;, or better yet std::string_view.  (Though in the case of a properly written constructor (see below) you might want to do something more advanced here.)

enemies = MonsterCluster(0, &quot;Goblin&quot;, 20, 5);
enemies = MonsterCluster(1, &quot;Wraith&quot;, 50, 10);
enemies = MonsterCluster(2, &quot;Legionare&quot;, 80, rand() % 60+20);

You are assigning values to the same variable, overwriting the previous.
I think you're confusing the meaning of monsterList inside the class with uses of the entire class.  Each instance you create is populating a different element in the array, but you don't understand that these calls are creating different instances and not updating the previous instance!  You throw away the first two instances you create and only keep the third.
Have a Monster class with a constructor.  You don't show your Monsters but it appears to be a plain struct without a constructor, from how you're using it.
Then you don't need a class that's nothing but a collection of 3 Monsters.  That's just an array.
Something like:
Monster enemies[] = {
   { &quot;Goblin&quot;, 20, 5 },
   { &quot;Wraith&quot;, 50, 10 },
   { &quot;Legionare&quot;, 80, rand() % 60+20 }
};

Note that each line is three parameters for the Monster constructor.