title: Friend function inside class and outside class, what difference does it make?
body: <pre><code>#include&lt;iostream.h&gt;
  #include&lt;conio.h&gt;
  class time
  {
      private:
          int dd,mm,yy;
      public:
          friend istream &amp; operator &gt;&gt;(istream &amp;ip,time &amp;t)
          {
              cout&lt;&lt;"\nEnter Date";
              ip&gt;&gt;t.dd;
              cout&lt;&lt;"\nEnter Month";
              ip&gt;&gt;t.mm;
              cout&lt;&lt;"\nEnter Year";
              ip&gt;&gt;t.yy;
              return ip;
          }
          friend ostream &amp; operator &lt;&lt;(ostream &amp;op,time &amp;t)
          {
              op&lt;&lt;t.dd&lt;&lt;"/"&lt;&lt;t.mm&lt;&lt;"/"&lt;&lt;t.yy;
              return op;
          }
  
          void validate();
  };
  
  void time::validate()
  {
  }
  int main()
  {
      clrscr();
      time t1;
      cin&gt;&gt;t1;
      cout&lt;&lt;t1;
      getch();
      return 0;
  }
  </code></pre>
  
  <p>What difference does it make? When I define the friend function outside the class the compiler is giving an error but when I define it inside a class it works perfectly fine.</p>
  
  <p>Note: I am using Turbo C++. I know that's old school, but we are bound to use that.</p>