You could get away with it, but it certainly never is a good thing, especially if allocated on the stack.
You have two undefined behavior there. Delete this on a class allocated on the stack and trying to access the class's contents after it's been deleted. No wonder you get a crash.

Originally Posted by Adak

io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.

Originally Posted by Salem

You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

As Elysia correctly points out, doing "delete this" when "this" is a pointer to an object that was not created with new, then you are ALSO performing something bad in this situation - that would definitely cause a big problem in one way or another. I should have spotted that too.

But it's also not particularly meaningful to do delete this in a case where the object has been allocated using new.

--
Mats

Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.

But it's also not particularly meaningful to do delete this in a case where the object has been allocated using new.

I think that depends. You can find solutions where it might work, such as MFC's CWinThread, which, by default, deletes itself when the thread has finished executing. But I would like to rely more on smart pointers, however.

Originally Posted by Adak

io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.

Originally Posted by Salem

You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

Thanks matsp and Elysia!
I was thinking ... if I don't access any data member after doing delete this then it will work fine!
But in this case, as Elysia pointed, that will delete a memory which was never newed.
So I think it will still fail.