title: C++ virtual functions implementation outside the class
body: <p>I am new to C++. While trying sample polymorphism code, I found that base class virtual function definition in derived class is possible only when defined within the derived class or outside with declaration in derived class. </p>
  
  <p>Following code gives error:</p>
  
  <pre><code>class B
  {
  public:
      virtual void f();
  };
  
  void B::f() {
      std::cout&lt;&lt;"B::f";
  }
  
  class D : public B
  {
  public:
      void f2() {int b;}
  };
  
  // error: no "void D::f()" member function declared in class "D"
  void D::f() {
      std::cout&lt;&lt;"D::F";
  }
  </code></pre>
  
  <p>It works if I declare f() inside D. I was wondering why do I need to explicitly declare the function again when it is already declared in Base class. The compiler can get the signature from Base class right? </p>
  
  <p>Thanks in advance..</p>