Tarquila Tarquila - 1 year ago 86
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?

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download