Is there anything wrong when deleting an object like this in C++?
MyCls* c = new MyCls();
void* p = (void*)c;
delete (MyCls*)p;
This as written is legal.
The cast back to MyCls*
is critical. Without that, you will invoke undefined behavior--the MyCls destructor will not be called, and other problems may arise as well (such as a crash). You must cast back to the correct type.
Also note that this can be complicated if multiple inheritance is involved and multiple casts are used. Your casts must "match" in either direction.
If your code is structured such that you won't know the type at the time of destruction, give each deletable object a common base class with a virtual destructor. Then cast back to the base class before delete is called.