title: Why virtual & static keywords aren't allowed outside class declaration?
body: <p>I am curious to know why following isn't allowed in C++?</p>
  
  <p>1st program:</p>
  
  <pre><code>#include &lt;iostream&gt;
  class Test {
      public:
          int myfun();
  }
  virtual int Test::myfun()
  { return 0; }
  int main()
  { }
  </code></pre>
  
  <p>[Error] 'virtual' outside class declaration</p>
  
  <p>2nd program:</p>
  
  <pre><code>#include &lt;iostream&gt;
  class Test {
      public:
          int myfun();
  };
  static int myfun() {
      std::cout&lt;&lt;"This program contains an error\n";
      return 0; 
  }
  int main() {
    Test::myfun(); 
    return 0; 
  }
  </code></pre>
  
  <p>[Error] cannot call member function 'int Test::myfun()' without object</p>
  
  <p>So, my questions are</p>
  
  <p>Why can't I make a member function virtual like as in 1st program?</p>
  
  <p>Why can't I make a member function static like as in 2nd program?</p>
  
  <p>Is there any reason to not allow these 2 keywords outside the class?</p>