Note that there are some explanatory texts on larger screens.

plurals
  1. POClass has virtual method but non virtual destructor C++
    primarykey
    data
    text
    <blockquote> <p><strong>Possible Duplicate:</strong><br> <a href="https://stackoverflow.com/questions/127426/gnu-compiler-warning-class-has-virtual-functions-but-non-virtual-destructor">GNU compiler warning &ldquo;class has virtual functions but non-virtual destructor&rdquo;</a> </p> </blockquote> <p>I am writing an interface for two classes and I get the warning in the title. Here's the code:</p> <pre><code>class GenericSymbolGenerator { protected: // &lt;== ok ~GenericSymbolGenerator(void) {} public: virtual GenericSymbolTableCollection* generateSymbolTableCollection(GenericSymbolTableCollection *gst) = 0; GenericSymbolGenerator(void) {} // ~GenericSymbolGenerator(void) {} // &lt;== warning if used }; class PascalPredefinedSymbolGenerator : public GenericSymbolGenerator { protected: ~PascalPredefinedSymbolGenerator(void) {} // &lt;== ok public: GenericSymbolTableCollection* generateSymbolTableCollection(GenericSymbolTableCollection *pst); // initializes *pst PascalPredefinedSymbolGenerator(void) {} // ~PascalPredefinedSymbolGenerator(void) {} &lt;== warning if used }; class PascalSymbolGenerator : public GenericSymbolGenerator { protected: ~PascalSymbolGenerator(void) {} // &lt;== ok public: GenericSymbolTableCollection* generateSymbolTableCollection(GenericSymbolTableCollection *st); // initializes st PascalSymbolGenerator(void) {} // ~PascalSymbolGenerator(void) {} // &lt;== warning if used }; </code></pre> <p>As long as the constructor/destructor is void there is no issue in declaring the destructor as protected. The problem arises when the class makes use of the heap(the destructor being declared as protected there is no way of freeing the class from the "outside" making the object "indestructible"). Is there a more convenient approach(aside from going public all the way)?</p>
    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.
 

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