| | |
Creating objects within objects dynamically
Please support our C++ advertiser: Intel Parallel Studio Home
![]() |
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]". 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[i]);
But how do I go about creating useable names dynamically? The only thing I can think of is anims[i].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
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]". 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[i]);
But how do I go about creating useable names dynamically? The only thing I can think of is anims[i].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
Last edited by phalaris_trip; Dec 2nd, 2007 at 7:19 pm.
>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:
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:
C++ Syntax (Toggle Plain Text)
anims["AnimNormal"];
I'm here to prove you wrong.
![]() |
Similar Threads
- Creating a popup menu on mouse over (JavaScript / DHTML / AJAX)
- using hash in perl objects (Perl)
- Object Oriented Design (PHP)
- Dynamic class members? (C++)
- How to delete a data structure in Builder 6.0? (C++)
- Regarding ASP.NET worker process (ASP.NET)
- Dynamic memory allocation homework (C++)
Other Threads in the C++ Forum
- Previous Thread: Searching a List of Structured Data
- Next Thread: c++ letter coding
| Thread Tools | Search this Thread |
api array beginner binary bitmap c++ c/c++ calculator char char* class classes coding compile compiler console conversion convert count data database delete desktop developer directshow dll dynamic dynamiccharacterarray email encryption error file forms fstream function functions game getline google graph homeworkhelper iamthwee ifstream input int integer java lib linkedlist linker linux list loop looping loops map math matrix memory multiple news node number numbertoword output parameter pointer problem program programming project proxy python random read recursion recursive reference return rpg sorting string strings struct template templates test text tree unix url vector video visualstudio win32 windows winsock word wordfrequency wxwidgets






