title: Inheritance and virtual function can't compile (from Head First DP)
body: <p>I am new to Design Pattern, and I'm trying the first example of (Head First Design Patterns) but I'm trying to code it in C++. I can't compile my code! I don't know why. Here's my code.</p>
  
  <pre><code>#include &lt;iostream&gt;
  using namespace std;
  
  class QuackBehavior
  {
  public:
      virtual void quack();
      virtual ~QuackBehavior();
  };
  class Quack : public QuackBehavior
  {
  public:
      void quack()
      {
          cout&lt;&lt;"Quacking"&lt;&lt;endl;
      }
  };
  
  class MuteQuack : public QuackBehavior
  {
  public:
      void quack()
      {
          cout&lt;&lt;"&lt;&lt;&lt; Silence &gt;&gt;&gt;"&lt;&lt;endl;
      }
  };
  
  class Squeak : public QuackBehavior
  {
  public:
      void quack()
      {
          cout&lt;&lt;"Squeak"&lt;&lt;endl;
      }
  };
  
  class FlyBehavior
  {
  public:
      virtual void fly();
      virtual ~FlyBehavior();
  };
  
  class FlyWithWings : public FlyBehavior
  {
  public:
      void fly()
      {
          cout&lt;&lt;"I'm flying"&lt;&lt;endl;
      }
  };
  
  
  
  class FlyNoWay : public FlyBehavior
  {
  public:
      void fly()
      {
          cout&lt;&lt;"I can't fly"&lt;&lt;endl;
      }
  };
  
  class Duck
  {
  public:
      FlyBehavior *flyBehavior;
      QuackBehavior *quackBehavior;
  
      void display();
      void performFly()
      {
          flyBehavior-&gt;fly();
      }
      void performQuack()
      {
          quackBehavior-&gt;quack();
      }
  
  };
  
  class MallardDuck : public Duck
  {
  public:
      MallardDuck()
      {
          quackBehavior = new Quack();
          flyBehavior = new FlyWithWings();
      }
  };
  
  
  
  int main()
  {
  
      Duck *mallard = new MallardDuck;
  
      cout&lt;&lt;"Test"&lt;&lt;endl;
  
      mallard-&gt;performFly();
  //  mallard-&gt;performQuack();
  
      return 0;
  }
  </code></pre>
  
  <p>Thanks for your help.</p>