title: function is inaccessible (C++)
body: <p>I'm working on some code to understand some design patterns. I'm working on C# and on C++ to better understand both languages. The following code gives the error that Duck::fly() and Duck::quack() is not accessible. Could anyone help me with this error? </p>
  
  <pre><code>#include "stdafx.h"
  #include "iostream"
  #include "string"
  
  using namespace std;
  
  int main()
  {
      std::cout &lt;&lt; "Object Oriented Pattern:\n\n";
  
      MallardDuck Duck1;
      Duck1.fly();
      Duck1.quack();
  
      RubberDuck Duck2;
      Duck2.fly();
      Duck2.quack();
  
      std::cin.get();
      return 0;
  };
  
  class IFlyBehavior
  {
  public:
      virtual void fly();
  };
  
  class IQuackBehavior
  {
  public:
      virtual void quack();
  };
  
  class Duck
  {
  protected:
      IFlyBehavior FlyBehavior;
      IQuackBehavior QuackBehavior;
  
  public:
      void fly()
      {
          FlyBehavior.fly();
      }
      void quack()
      {
          QuackBehavior.quack();
      }
  };
  
  class RubberDuck : Duck
  {
  public:
      RubberDuck() : Duck()
      {
          NoFly FlyBehavior;
          Squeak QuackBehavior;
      }
  };
  
  class MallardDuck : Duck
  {
  public:
      MallardDuck() : Duck()
      {
          FlyWithWings FlyBehavior;
          Quack QuackBehavior;
      }
      ~MallardDuck() { };
  };
  
  class FlyWithWings : IFlyBehavior
  {
      void fly()
      {
          cout &lt;&lt; "Flapping wings.";
      }
  };
  
  class NoFly : IFlyBehavior
  {
      void fly()
      {
          cout &lt;&lt; "Can't fly.";
      }
  };
  
  class Quack : IQuackBehavior
  {
      void quack()
      {
          cout &lt;&lt; "Quack!";
      }
  };
  
  class Squeak : IQuackBehavior 
  {
      void quack()
      {
          cout &lt;&lt; "Squeak!";
      }
  };
  </code></pre>
  
  <p>I have no idea why this is inaccessible since the function in duck is declared as public. </p>
  
  <p>By the way: is there a way to copy the code into a code block? I had to put all spaces in front of everything now. So is there an easier way to do this? </p>
  
  <p>Kind regards,</p>
  
  <p>Bob</p>