Hej
Abstrahując od tego, że nikt tak nie robi bo to jest dziwne (używamy delete albo inteligentnych wskaźników) to czy z punktu widzenia odporności na memory leaki to jest poprawne kasowanie obiektu przez jawne wywołanie destruktora?
#include <stdio.h>
#include <iostream>
#include <memory>
class Base
{
public:
virtual ~Base()
{
std::cout << "Base dtor" << std::endl;
//delete of same dynamic allocated resources
}
};
class Inherited: public Base
{
public:
virtual ~Inherited()
{
std::cout << "Inherited dtor" << std::endl;
//delete of same dynamic allocated resources
}
};
int main()
{
Base* base = new Inherited();
base->~Base(); //Inherited dtor, base dtor invoked, the same effect as 'delete base'
//if none virtual Base dtor only Base dtor invoked -> memory leak
}