title: Putting class declaration in .cpp file
body: <p>Is it possible to have class declaration and implementation in same .cpp file?</p>
  
  <p>I want to do some unit-testing with help of mock object. Here is some example of my test:</p>
  
  <pre><code>// Some includes removed
  
  #include "abstractconnection.h"
  
  class ConnectionMockup : public AbstractConnection
  {
      Q_OBJECT
  public:
      explicit ConnectionMockup(QObject *parent = 0);
  
      bool isReady() const;
      void sendMessage(const QString &amp;message);
  
      void test_send_message(const QString &amp;message);
  
      bool ready;
      QStringList messages;
  };
  
  ConnectionMockup::ConnectionMockup(QObject *parent)
      : AbstractConnection(parent)
  {
      ready = true;
  }
  
  bool ConnectionMockup::isReady() const
  {
      return ready;
  }
  
  void ConnectionMockup::sendMessage(const QString &amp;message)
  {
      messages.append(message);
  }
  
  void ConnectionMockup::test_send_message(const QString &amp;message)
  {
      emit messageRecieved(message);
  }
  
  TestEmcProgram::TestEmcProgram(QObject *parent) :
      QObject(parent)
  {
  }
  
  void TestEmcProgram::open()
  {
      ConnectionMockup mockup;
      EmcProgram program(&amp;mockup);
      QCOMPARE(...
  ...
  ...
  </code></pre>
  
  <p>As you can see, the class ConnectionMockup is only used by class TestConnection, and I don't need it anywhere else. So, when I try to compile this program, I get following error:</p>
  
  <pre><code>&gt; testemcprogram.o: In function  
  &gt; `ConnectionMockup':  
  &gt; /home/sasa/Desktop/QtPro/FocoKernel-build-desktop/../FocoKernel/testemcprogram.cpp:29:  
  &gt; undefined reference to `vtable for  
  &gt; ConnectionMockup'  
  &gt; /home/sasa/Desktop/QtPro/FocoKernel-build-desktop/../FocoKernel/testemcprogram.cpp:29:  
  &gt; undefined reference to `vtable for  
  &gt; ConnectionMockup' testemcprogram.o: In  
  &gt; function `~ConnectionMockup':  
  &gt; /home/sasa/Desktop/QtPro/FocoKernel-build-desktop/../FocoKernel/testemcprogram.cpp:14:  
  &gt; undefined reference to `vtable for  
  &gt; ConnectionMockup'
  </code></pre>
  
  <p>Is it possible to leave declaration here, or I must create header file and move declaration in to that file?</p>
  
  <p><strong>EDIT:</strong> Since Mr. Jerry Coffin (thank you Mr. Coffin) suggested that I may not have some virtual functions implemented, I will put here declaration of AbstractConnection so we could review that possibility:</p>
  
  <pre><code>#include &lt;QObject&gt;
  
  class AbstractConnection : public QObject
  {
      Q_OBJECT
  public:
      explicit AbstractConnection(QObject *parent = 0);
      virtual ~AbstractConnection();
  
      virtual bool isReady() const = 0;
  
  signals:
      void messageRecieved(const QString &amp;message);
  
  public slots:
      virtual void sendMessage(const QString &amp;message) = 0;
  
  };
  </code></pre>
  
  <p><strong>SOLUTION:</strong> Thanks to @JCooper, @iammilind and @Jerry Coffin we have the solution. After removing destructor from AbstractConnection (since it actually does nothing) and removing Q_OBJECT from ConnectionMockup it works.</p>