So let's say I have a class called CSprite which loads a sprite sheet. Within that class will be at least one CAnimation object which takes user-defined snippets from the sprite sheet and loops them.. so for example I might want:
CAnimation m_AnimNormal, m_AnimOnFire;
inside the actual CSprite object.

The problem is that I might have 20 or 30 such loops per sprite sheet. So I will need a vector (std::vector<CAnimation> anims) or something, but I don't want the programmer to just refer to them as "anims". I would like meaningful names, so that later I can just say something like:
m_Sprite.DisplaySurface(m_AnimNormal);
instead of
m_Sprite.DisplaySurface(anims);

But how do I go about creating useable names dynamically? The only thing I can think of is anims.push_back(whatever), which isn't very descriptive.

Of-course I could delve into strings and associate some string in a separate vector with each animation object and then set up a for loop to check the strings each time... but for some reason this seems like the wrong way to go about it...

Cheers

>But how do I go about creating useable names dynamically?
Use a map instead of a vector, then you can use a string to index the map instead of an integer, which makes things more meaningful:

anims["AnimNormal"];

So you mean something like std::map <const char*, CAnimation> anims; ?

Never used them before but yeah I guess that would do the trick.. thanks for quick reply,

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.