In C++ classes, why the semi-colon after the closing brace? I regularly forget it and get compiler errors, and hence lost time. Seems somewhat superfluous to me, which is unlikely to be the case. Do people really do things like:
class MyClass { . . . } MyInstance;
I get it from a C compatibility point of view for structs and enums, but since classes aren’t part of the C language I guess it’s primarily there the keep consistency between similar declaration constructs.
What I was looking for was more related to design rationale rather than being able to change anything, although a good code completion IDE might trap this before compilation.
The semi-colon after the closing brace in a type declaration is required by the language. It’s been that way since the earliest versions of C.
And yes, people do indeed do the declaration you just put up there. It’s useful for creating scoped types inside of methods.
In this case, I think it’s clear why the semi-colons are needed. As to why it’s needed in the more general case of declaring in the header file I’m unsure. My guess is that it’s historical and was done to make writing the compiler easier.