   Vectors of objects
  I hope that I am putting this thread in the right place, but it really falls under several categories, I guess.I currently have a class Level, and one of its variables is a vector of objects of class Player. The Player class has many different attributes, and they are all working great, save one.  I am using OpenGL, so I am loading the sprite sheet for the Player into a texture GLuint.This works great in other things I do, but I cannot get it to work right here.  I also have setup a destructor for the Player class, and this deletes that texture. Whenever a new level is loaded, the vector of Players is cleared, which in my understanding also calls all of their destructors. Then new Players are generated.The Player class's destructor seems to be the problem.  If I simply remove the line that deletes the texture, everything works.  So, I guess my first question is, is it possible that this destructor is being called at some point for some reason that I do not understand?   
  Well, the copy constructor will be called, and then the destructor will be called for each element any time the vector resizes.vector grows ~exponenially. So operations like .push_back will cause a resize every once in a while, but much more often while the vector is small.Really you need something like a smart pointer for the texture resource, or your own functionality that is equivelent.  Google the c++ "rule of 3" to see more on what you need to do to write the code correctly.   ;  Also, when you push_back a new element you have to specify an object, that object then gets copied to another one within the vector, if the initial object was a temporary one then its destructor will be called once the function finishes:vec.push_back( foo("I am temporary and will be copied") );   ;  If more than one instance of the class uses the same texture, then an alternative to having the class worrying about the texture is to have a single texture manager for the app. The texture manager maintains a reference count for each texture. In the Player class constructor, it tells the tex mgr, "I need texture X." Tex mgr increases the reference count for texture X by 1 and returns the GLuint. In the Player class destructor, it tells the tex mgr, "I'm done with texture X" and the tex mgr decreases the reference count for texture X by 1. When the reference count reaches 0, it unloads the texture.Tex mgr also takes care of the loading the texture when it's requested if it's not available. That will be invisible to the classes.;  Thanks for the help everyone.  I got it working again, but I want to clean it up a bit.  Your idea sounds great, Buckeye, thanks!   