samedi 23 septembre 2017

How to show name of instance in c++?

I am trying to output the names of the monsters that have been instantiated (and moved into a vector).

I also need to randomize the positions of the monsters before output-ing the names.

the code I have for randomizing them is:

random_shuffle(monsters.begin(), monsters.end());
for (vector<Unit*>::iterator it = monsters.begin(); it != monsters.end(); ++it) cout << " " << *it;

but it only outputs the address of them and not the name, probably because they aren't strings (?)

What is a way for me to output the names when they've been instatiated like this:

Monster *deyvor = new Monster("Deyvor", 2000); 

"deyvor" being the name and "2000" being the amount of strength it has.

I was thinking of creating a function that gets the name so I can do something like it->getName() but I am also unsure of how to do it.


I also added them into a vector by doing this:

monsters.push_back(Deyvor);




Aucun commentaire:

Enregistrer un commentaire