   C++: Accessing container members
  As I begin writing a C++ class that contains an STL list and a vector, I'm realizing that I have no idea what the best practices are for accessing private container members.  As a very basic example, if I want to iterate through the list and print all of the contents, do I want the iterator to be another member of the class?  Or do I declare it outside of the class scope and have it "point to" the list member?The latter seems to violate encapsulation principals all over the place, but I'm not sure if I'm going to take a big performance hit on the former if I have to keep calling member functions every time I want to manipulate an iterator.Any thoughts?  I'm not sure how well I'm explaining this, so please let me know if I can provide more information.Thanks!   
  The real question is: why do you need to access the lists outside of the class? And if you do, are you sure they should be inside the class in the first place?Also, you can always just write functions that return references to the lists, and access them that way.   ;  Or you can write functions that return the types of iterators you want outside classes to have access to for the internal members.   ;  It's all part of deciding on the semantics of the class.Is the class meant to be a container itself (which happens to be implemented in terms of a list and a vector)? In which case the class is meant to be modelling an iterable collection so it probably ought to expose begin() and end() members to allow for iteration.Otherwise if the semantics of the class don't call for it to be iterable then probably the operations you perform on the underlying containers are meant to be part of the class, so add a member to the class itself to allow for printing; a common form for such a member to take is to overload the stream operator: operator<<().   ;  Thanks for all the suggestions, reading them makes me think I need to more carefully plan this class.The class in question is a bullet manager for a bullet hell shmup I'm working on.  Rather than constantly constructing/destructing bullets, I have a large vector of bullets that I initialize before the game begins, and then maintain lists of "Active" and "Inactive" bullets (which are simply indices for the master vector).Where I'm running into trouble is when I try to decide what the scope of this class should be.  I have a solid collision detection function written, but I don't know where I should be calling it from.  When detecting collisions between player bullets and enemy ships, I see two viable options:1) Create iterators outside of the class that point to the underlying lists/vector.  Use them to iterate through each bullet and do something like detect_collision( *currentBulletIter, *currentEnemyShip )2) Handle collision detection in the bullet manager class...bulletManagerInstance.detectCollisions( list<EnemyShip *> & listOfEnemyShips )and let the class handle everything.  I see drawbacks to each method.  The first requires creating a lot of iterators outside the class and things like "deactivating" a bullet aren't as simple when you're not working within the class scope.  The second method seems... wrong.  My collision detection function is general and doesn't seem like it would "belong" in the bullet manager class.In any case, I think I'll just have to hammer away at this and post more specific questions once I try a few things on my own.  Thanks again for the help!  If anyone has any input on the two methods I mentioned, it would be much appreciated!;Quote:Original post by matriskingThe class in question is a bullet manager for a bullet hell shmup I'm working on.  Rather than constantly constructing/destructing bullets, I have a large vector of bullets that I initialize before the game begins, and then maintain lists of "Active" and "Inactive" bullets (which are simply indices for the master vector).1) Why are you doing your own object pooling when stock solutions exist?2) Do you already know you need this "optimization"? Have you tried it the other way? Don't take on extra complexity unnecessarily.3) How is going through a list of indices going to perform any better than just tagging the bullet instances themselves with an 'active' boolean? For that matter, have you considered actually putting the bullets directly into two std::lists (list specifically so that they aren't moved around in memory when activated/deactivated)?   ;In this in-depth interview, NeverDead director Shinta Nojiri explains why he left Metal Gear Solid studio Kojima Productions to take a job developing a new IP -- and ended up relocating to England to work with the team at Rebellion on the title.  View the full article