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

后端 未结 6 645
旧巷少年郎
旧巷少年郎 2020-12-01 09:22

In a C++ class declaration:

class Thing
{
    ...
};

why must I include the semicolon?

6条回答
  •  广开言路
    2020-12-01 09:35

    Because it could be a definition of the next element. For example, taking it from C syntax: if you declare

    struct { ... } main (int argc, char..

    then it assumes main returns a struct. If there was a semicolon,

    struct { ... }; main (int argc, char..

    then main returns an int.

提交回复
热议问题