Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Semicolon after classes and structs [duplicate]

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?

like image 247
sharkin Avatar asked Nov 23 '09 22:11

sharkin


People also ask

Why is there a semicolon after struct?

A semicolon after a close brace is mandatory if this is the end of a declaration. In case of braces, they have used in declarations of class, enum, struct, and initialization syntax. At the end of each of these statements, we need to put a semicolon.

Do structs require semicolons?

At the end of a struct definition a semicolon is not required. However at the end of a struct tuple it is.

What does semicolon after while loop mean?

When you first start working with while statements, you might accidentally place a semicolon after the “while(true/false expression)” part of the statement such as shown below. The semicolon results in a null statement, a statement that does nothing.


1 Answers

Because the next word following the } may declare a variable of said type. This is a relic from C:

struct S { int a; } s;
s.a;
like image 88
Jonathan Graehl Avatar answered Oct 05 '22 18:10

Jonathan Graehl