Why does C++ have a “;” after a class declaration

2020-08-15 02:00发布

I'm starting to learn C++ and just out of curiosity, why does C++ require you to put a ";" at the end of the class declaration for example:

class A
{
   /*...*/
};

In languages like java, it's used to signify an end of a statement.

What is different about

int i(5);

and the class above with regards to the semi-colon in C++? Does the compiler treat the class as a statement or does it have a different interpretation for it?

标签: c++
1条回答
啃猪蹄的小仙女
2楼-- · 2020-08-15 02:35

because you can also define variables in the declaration:

class A {
        ...
} x, y, z;

Ending class declarations in a semicolon is basically saying explicitly that we are not declaring any variables of this type.

查看更多
登录 后发表回答