This is perfectly working and I cant figure out why:
#include <iostream>#include <string>class SomeClass{ public: void printHello() { std::cout << "hello" << std::endl; }};int main(){ SomeClass *myClass = new SomeClass; delete myClass; myClass->printHello(); return 0;}
I'm expecting a segfault or at least that nothing is actualy printed on the screen, but everything just work as not intended...
However this do segfault:
#include <iostream>#include <string>int main(){ std::string *myString = new std::string("hey there"); delete myString; std::cout << *myString << std::endl; return 0;}
Basicly if I allocate a class of my own and delete it, it is not deleted, when sl or stl class are.
Im running g++ 4.5.1 on linux.
Any idea? Thank you.