Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Ekim_Gram

How do you create an object where the user decided what it's name is? (c++)

This topic is 5546 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Say you have the typedef of the following object:
typedef class Player()
{
 public:
 Player();
 Player(int age);
 int setAge(age);
 void Attack();
 private:
 int hp;
} o_Player;

If I have errors there please tell me. Now, say I the user wants to create a new one of those classes for one reason or another, how would I use a string or char to initialize a new class's name using the typedef above?
There's no town drunk here, we all take turns. Velocity Gaming Force [edited by - Ekim_Gram on August 15, 2003 10:10:07 PM]

Share this post


Link to post
Share on other sites
Advertisement
Why do you want to typedef that class for??

And why do you want a user to be able to name the variable?

If you have a collection of players then the user can name them via a member variable but the actual instances of the class should just be stored in a collection, like a link list of something.

Share this post


Link to post
Share on other sites
It's not possible (this is just like the Naming VARIABLES thread). What you can do is use a hash table or std::map to associate strings with unnamed player objects. If you don't know how, google for the SGI STL docs and find the map documentation. Or maybe someone less lazy than I can show you how. ^_^

Frankly, it's incredibly annoying that you can't do this sort of thing in C++, but it's unavoidable in such a static language.

[edited by - twix on August 15, 2003 10:25:31 PM]

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!