G
gopal
Why is ; ~ semi-colon used at the end of class definition ?
Thanks JK
Thanks JK
gopal said:Why is ; ~ semi-colon used at the end of class definition ?
Why is ; ~ semi-colon used at the end of class definition ?
C++ uses ; to tokenize the strings.gopal said:Why is ; ~ semi-colon used at the end of class definition ?
Thanks JK
C++ uses ; to tokenize the strings.
This means that until the C++ compiler sees ';'
The same goes for english, when we sees full stop, we know its the end
of that phrase.
Hope this helps!!!
Then why is there no ';' at the end of function implementations?
Robert Bauck Hamar said:No, the ; is a token. C++ uses it as a syntactic element.
Then what? You can write a lot of code without the use of any ';'.
Short answer: Because the syntax says so. A language's syntax rules are
different from language to language. A lot of languages have 'then' as a
keyword used with 'if'. Some languages use ':=' for assignment while
others
use '<-'.
Much of the syntax for C++ is inherited from C, where 'struct'
declarations
has a ';', and function definitions does not. In C++, the syntax for
classes is the same as for structs, except for the keyword.
Another answer:
class foo { }
is a type, and can be used like:
class foo { } a, b;
which also defines a and b to be of type foo.
void bar() { }
is not a type, however.
JohnQ said:So does the ';' at the end of a class/struct definition make it easier to
parse or is it unnecessary? (I'd tend to think that it is unnecessary
since the brackets are there).
Robert said:Short answer
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.