class base
{
virtual ~base();
};
class der1 :public base
{
int i;
}
class der2 :public base //I used double that der2 is bigger than der1
{
double d;
}
int main()
{
base* ptr = new der2;
ptr->~base(); //Destructor call just for the
//case that the der2 had a pointer member
der1* ptr2 = static_cast<der1*>(ptr);
*ptr2 = der1();
delete ptr;
return 0;
}
What would happen if you would execute the code shown above? Would this produce a memory leak and if yes why? Is there a possibility to use the taken memory for different types without releasing it first? (Please no answers like why should you need this, it's just interest)
Edit: The ~base() does nothing because this is an example.