Search code examples
c++syntaxlanguage-design

Semicolon after classes and structs


Possible Duplicate:
Why must I put a semicolon at the end of class declaration in C++?

Found duplicate, vote to close please.

Why do classes and structs have to be concluded with semicolon in C++?

Like in the following code:

class myClass
{



};

struct muStruct
{

};

This syntax isn't necessary in Java or C#. Why does the C++ parser need it?


Solution

  • This is why...

    int a,b,c,d;
    int main(void) {
        struct y {
      }; a, b, c, d;
        struct x {
      } a, b, c, d;
    }
    

    Two different statements, two completely different meanings, both legal C / C++, and the only difference is the ; after the struct declaration.