opengl - Deleting global object in game.(C++) -
i making bubble pop game in c++ user clicks on randomly generated bubbles float screen(still in development). in order use opengl , glut game found best make bubbles global. have blank destructor not know how delete contents of bubble , create new one. tried using dynamic allocation didn't make difference. how can delete contents of bubble , make new one?
here's necessary snippet: main.cpp
bubble mybubble1; void display(void) { delete mybubble1;//error "cannot delete type bubble" }
my destructor here:
class bubble { public: //default constructor bubble() { radius=(rand() % 100 )+1; speed = rand() % 500 ; xval = rand() % 480; yval= -14; islive=true; } ~bubble() { } private: float radius; float speed; float xval; float yval; bool islive; };
the code runs fine when don't try delete anything. can run infinite looping bubbles
you not using pointers in bubble
destructor can stay blank. if want reassign bubble
so
bubble mybubble1; //use mybubble1 ... mybubble1 = bubble();
Comments
Post a Comment