I'm using SDL to create a pretty simple Pong game. For the collision detection, I have a class called DetectCollision which looks like this:

class DetectCollision { public: std::vector<Object*> objects; int numOfObjects; DetectCollision(); ~DetectCollision(); void takeObjs(Object &); void handleCollision(); };

So what happens is the takeObjs(Object &) function takes an object of the Object class and stores it in a vector. takeObjs(Object &) looks like this:

void DetectCollision::takeObjs(Object &obj1){ objects.push_back(&obj1); }

Everything works up to this point. I'm able to access the vector "objects" to detect all the collisions and it works fine, but the problem comes when I am trying to delete the vector. If I'm not mistaken, it's a vector of pointers. So what I did to delete it is in the class destructor:

DetectCollision::~DetectCollision(){ for (unsigned int i = 0; i < objects.size(); ++i){ delete objects[i]; } objects.clear(); }

According to the Code::Blocks IDE using a GCC compiler, it segfaults on the "delete objects[i];" line. It also segfaults on another part of the program to attempts to SDL_FreeSurface() the skins held by the class, but I think I can fix that one easily enough. This vector is the main issue. If you need to look at the full source code to help me learn how to fix the issue, I can provide that. I am very grateful for any assistance. Thanks and DFTBA!