Is it really important to put that semicolon there and if, why?
Yes. This can be useful sometime.
You can define a struct, and can declare an object as:
struct A
{
//members
} obj;
obj
is an object of type A
, and you declare this just as shown above. It is in same way you put semicolon after declaring variables, such as:
int i; //declares i of type int
std::string s; //declares s of type std::string
struct {int x,y,z;} point; //declares point of an unnamed struct type
Here first two declarations look very familiar, but the last one looks slightly unfamiliar, as it defines an unnamed struct, and simultaneously declares an object called point
of the unnamed struct.
The bottomline is that you put a semicolon after declaring objects uniformly, no matter how you declare the objects, no matter what their types are.
Not only that you can even typedef
in a uniform way:
typedef int my_int;
typedef std::string my_string;
typedef struct {int x,y,z;} my_point;
Now all of these my_int
, my_string
, and my_point
are types.
But when you do neither of them (i.e neither declaring objects, nor defining typedefs), then you simply leave the place as such, blank, with no declaration/definition whatsoever. But the point to be noted is that it gives you an interesting and useful feature all along.