Tarquila Tarquila - 1 month ago 4x
C++ Question

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

In a C++ class declaration:

class Thing

why must I include the semicolon?


The full syntax is, essentially,

class NAME { constituents } instances ;

where "constituents" is the sequence of class elements and methods, and "instances" is a comma-separated list of instances of the class (i.e., objects).


class FOO {
  int bar;
  int baz;
} waldo;

declares both the class FOO and an object waldo.

The instance sequence may be empty, in which case you would have just

class FOO {
  int bar;
  int baz;

You have to put the semicolon there so the compiler will know whether you declared any instances or not.

This is a C compatibility thing.