title: C++ "Virtual functions but no virtual destructors"
body: <p>I have a base class <code>Media</code> and several derived classes, namely <code>DVD</code>, <code>Book</code>, etc...
  The base class is written as:</p>
  
  <pre><code>class Media{
      private:
          int id;
          string title;
          int year;
      public:
          Media(){ id = year = 0; title = ""; }
          Media(int _id, string _title, int _year): id(_id), title(_title), year(_year) {}
  //      virtual ~Media() = 0;
          void changeID(int newID){ id = newID; }
          virtual void print(ostream &amp;out);
  };
  </code></pre>
  
  <p>The thing is: without the destructor, GCC gives me a bunch of warnings <code>class has virtual functions but non-virtual destructor</code>, but still compiles and my program works fine. Now I want to get rid of those annoying warnings so I satisfy the compiler by adding a virtual destructor, the result is: it doesn't compile, with the error:</p>
  
  <pre><code>undefined reference to `Media::~Media()`
  </code></pre>
  
  <p>Making the destructor pure virtual doesn't solve the problem.
  So what has gone wrong?</p>