W
W
WTFAYD2018-01-31 13:12:12
C++ / C#
WTFAYD, 2018-01-31 13:12:12

Why is there a semicolon after a class definition, but not after a function definition?

The essence of the question is very simple - why is there a semicolon after the class definition, but not after the function definition? At first I thought that this was due to the fact that both the declaration and the definition occur in one place, but, on the other hand, the situation is the same with the function.

struct Y
{
    // ...
}; 

void someFoo() 
{
    // ...
}

Answer the question

In order to leave comments, you need to log in

3 answer(s)
V
vreitech, 2018-01-31
@WTFAYD

a function definition always ends after the } symbol , but a class definition does not always.

A
Alexey Gordienko, 2018-01-31
@RdSpclL

Because in fact, a class declaration is a variable declaration (I don’t express myself quite correctly, but let’s say).
And in C++, when they write,
they put a semicolon.
similar:

class Foo 
{
int a_;
} foo;

only it is not necessary to write the variable name.
The gist is something like this.

M
Mercury13, 2018-01-31
@Mercury13

It went back to C. So, excuse me, there will be nothing positive, only "nice sishka".

// Переменная безымянного типа
struct {
  int x, y;
} point;

// Синоним для типа: вместо struct _Point можно писать просто Point.
typedef struct _Point {
  int x, y;
} Point;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question