As you can see, I used a shared_ptr pointer so that the memory that was allocated on the heap is automatically destroyed. I also included a virtual destructor. You should always do this even if your class isn't inherited. Otherwise, it is considered very very bad practice. If your compiler doesn't yet support C++11 smart pointers, use auto_ptr or just delete manually. I think you are using an older compiler as you used #include <iostream.h> instead of #include <iostream> .