Creating multiple objects with C++

  • Thread starter Thread starter Mon
  • Start date Start date

Mon

Mon

Associate
Joined
22 Oct 2002
Posts
636
Location
Bristol
Hi i'm currently doing a uni project in C++ and I need to create multiple objects with a user defined name.

In C I would just create an array in main to hold the objects... I just feel there should be a better way to do this in C++
 
You could use a hashmap collection, a set or anything. The key is how is it being accessed.

If the names are unique you could use the name as a hashable key direct to the object.

Check the standard C++ libs, I can't remember off the top of my head if a pre-written template already exists.
 
Thanks for the reply Going to have a read up on what you said although...

I am not 100% sure this is what i want to do , I have a class which i want to create multiple instances that the user names, this will be unique.

The trouble i am having is that one i have made the instances of the class I need to use methods within the class but to do this i need their name, and how do I do that without hard coding them into the program.
 
Back
Top Bottom