title: Why can I define structures and classes within a function in C++?
body: <p>I just mistakenly did something like this in C++, and it works. Why can I do this?</p>
  
  <pre><code>int main(int argc, char** argv) {
      struct MyStruct
      {
        int somevalue;
      };
  
      MyStruct s;
      s.somevalue = 5;
  }
  </code></pre>
  
  <p>Now after doing this, I kind of remembered reading about this trick someplace, a long time ago, as a kind of poor-man's functional programming tool for C++, but I can't remember why this is valid, or where I read it. </p>
  
  <p>Answers to either question are welcome!</p>
  
  <p>Note: Although when writing the question I didn't get any references to <a href="https://stackoverflow.com/questions/681068/declaring-structures-within-functions-in-c">this question</a>, the current side-bar points it out so I'll put it here for reference, either way the question is different but might be useful.</p>