Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I think you need to write <code>~Derive()</code> like this</p> <pre><code>~Derived() { delete some; some = 0; //this is must; so that `delete some` in ~Base() works perfectly; //note `delete (void*)0` is fine in C++! } </code></pre> <p><strong>Explanation :</strong> </p> <p>Why you need to write this even though the <code>~Base()</code> does the same thing <em>(it looks it does the same thing)</em> is because <code>~Derived()</code> <em>ensures</em> that you delete your object from the <strong>same</strong> heap/memory-pool/etc they were created on.</p> <p>See these topics:</p> <p><a href="https://stackoverflow.com/questions/4555961/how-to-use-a-class-in-dll/4556092#4556092">How to use a class in DLL?</a><br> <a href="https://stackoverflow.com/questions/4534679/memory-management-with-returning-char-function/4534706#4534706">Memory Management with returning char* function</a> </p> <hr> <h1>EDIT:</h1> <p>Better would be to add one more virtual function, say <code>deinit()</code>, (a counter-part of your <code>virtual void init()</code>) , redefine this too when you redefine <code>init()</code>, and do the de-allocation there in <code>deinit()</code>.</p> <pre><code>//DLL class Base { protected: Something *some; public: virtual void init() { some = new Something(); } virtual void deinit() { delete some; } virtual ~Base() { deinit(); } }; //EXE class Derived : public Base { public: virtual void init() { some = new SomethingElse(); } virtual void deinit() { delete some; //some=0 is not needed anymore! } }; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload