Re: Creating New Objects! (but not what you may think)
Okay, I'll try to be a wee bit less complicated than my main post.
Say you wanted to create a character. The character has three stats: Strength, Agility, and Wisdom. You also can name him.
So, is there something I can use to fill out a class like this:
class Character
{
public:
int strength;
int agility;
int Wisdom;
};
See what I mean? Having the ability to make an infinite amount of different, user-defined instances of a class. Or simply objects. If I'm making any sense whatsoever haha.
Re: Creating New Objects! (but not what you may think)
Sure. Just use new to create as many as you want. Overload the constructor to take the appropriate arguments. As I said in the first reply, if you want to be able to refer to them by some kind of name, use a map to map the pointers to the string name.
Re: Creating New Objects! (but not what you may think)
Originally Posted by Befall
Okay, I'll try to be a wee bit less complicated than my main post.
Say you wanted to create a character. The character has three stats: Strength, Agility, and Wisdom. You also can name him.
So, is there something I can use to fill out a class like this:
class Character
{
public:
int strength;
int agility;
int Wisdom;
};
See what I mean? Having the ability to make an infinite amount of different, user-defined instances of a class. Or simply objects. If I'm making any sense whatsoever haha.
Why not just make a constructor for your class, then make instances of it using new?
Re: Creating New Objects! (but not what you may think)
Think about how you post on this forum: you have some post content, maybe a post title, timestamp, etc.
Basically, you provide a user interface. Maybe the user has this "character management panel" where characters can be created. You might take the user input and create a Character object, perhaps to be stored in some container, and maybe also stored in a database.
C + C++ Compiler: MinGW port of GCC
Build + Version Control System: SCons + Bazaar
Re: Creating New Objects! (but not what you may think)
Originally Posted by Befall
Okay, I'll try to be a wee bit less complicated than my main post.
Say you wanted to create a character. The character has three stats: Strength, Agility, and Wisdom. You also can name him.
You could either set up a system which matched strings (names) with Character objects, like a std::map, or simply make the name just another attribute of the Character.
Bookmarks