C++

Virtual destructors

Në shqip: Destruktorët virtualë

ShpjegimiSQ

Nëse do të fshish objekte fëmijë përmes një pointer-i prindi, destruktori i prindit duhet të jetë virtual — përndryshe destruktori i fëmijës s'thërritet dhe memoria rrjedh.

EnglishEN

If you'll delete child objects through a parent pointer, the parent's destructor must be virtual — otherwise the child's destructor isn't called and memory leaks.

Si ta mendosh

Si t'i thuash pastruesit „pastro gjithë shtëpinë“, jo vetëm hyrjen.

Lexoje në anglisht

Like telling the cleaner “clean the whole house”, not just the hallway.

Shembull kodicpp

class Forme {
public:
    virtual ~Forme() = default;   // e domosdoshme
    virtual double siperfaqja() const = 0;
};

Terma të lidhur