title: can we define friend function inside the class in cpp
body: <ol>
  <li>according to rule we cant define  friend function inside the  class </li>
  <li>for istream and ostream we always declare friend function (so it is right) in below code </li>
  </ol>
  
  <p>But the problem for 1st point how it can be possible for
  given code to run successfully ....on GNU (ubuntu) compiler </p>
  
  <pre><code>#include&lt;bits/stdc++.h&gt;
  
  using namespace std;
  
  class dev{
      string str;
      int n;
  public:
      friend void operator &gt;&gt;(istream &amp;din,dev &amp;s1)
      {
          din&gt;&gt;s1.str&gt;&gt;s1.n;
      }
      friend void operator &lt;&lt;(ostream &amp;dout,dev &amp;s1)
      {
          dout&lt;&lt;s1.str&lt;&lt;" "&lt;&lt;s1.n;
      }
  };
  
  int main()
  {
      dev s2;
      cin&gt;&gt;s2;
      cout&lt;&lt;s2;
  }
  </code></pre>