title: Why can't I define a function inside another function?
body: <p>This is not a lambda function question, I know that I can assign a lambda to a variable.</p>
  
  <p>What's the point of allowing us to declare, but not define a function inside code?</p>
  
  <p>For example:</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  int main()
  {
      // This is illegal
      // int one(int bar) { return 13 + bar; }
  
      // This is legal, but why would I want this?
      int two(int bar);
  
      // This gets the job done but man it's complicated
      class three{
          int m_iBar;
      public:
          three(int bar):m_iBar(13 + bar){}
          operator int(){return m_iBar;}
      }; 
  
      std::cout &lt;&lt; three(42) &lt;&lt; '\n';
      return 0;
  }
  </code></pre>
  
  <p>So what I want to know is why would C++ allow <code>two</code> which seems useless, and <code>three</code> which seems far more complicated, but disallow <code>one</code>?</p>
  
  <p><strong>EDIT:</strong></p>
  
  <p>From the answers it seems that there in-code declaration may be able to prevent namespace pollution, what I was hoping to hear though is why the ability to declare functions has been allowed but the ability to define functions has been disallowed.</p>