1
General / Re: Storing Sprites In A Vector?
« on: November 12, 2014, 11:23:21 am »
Ahhhhhh, thanks guys.
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
QuoteInstead of doing this:This does almost the same thing as above, except it leaks memory because now the vector's destructor won't be able to clean up the copy of sprite1.std::vector<*Sprite> sprites;
Sprite sprite1;
sprites.push_back(&sprite1);
So I am wondering if there is any problems with this implementation.
The moral is: never use raw owning pointers in modern C++ without a VERY good reason. You won't need them. Also avoid using pointers of all kinds because you won't need any of them very often, and even smart pointers are always going to be more error prone than ordinary stack-based objects. If your program has no pointers in it, you simply can't make most of the common memory management mistakes.