JohnQ wrote:
:: "Robert Bauck Hamar" <ro**********@ifi.uio.nowrote in message
:: news:f8**********@readme.uio.no...
::: Juha Nieminen wrote:
:::
::::
gh********@gmail.com wrote:
::::: C++ uses ; to tokenize the strings.
:::
::: No, the ; is a token. C++ uses it as a syntactic element.
:::
::::: This means that until the C++ compiler sees ';'
:::
::: Then what? You can write a lot of code without the use of any ';'.
:::
::::: 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?
:::
::: 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.
::
:: 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).
No, it is necessary becase the class definition can optionally be
followed by declarations of variables of the class type. Look at foo
above, where the semicolon isn't terminating the class, but the list
"a, b". The semicolon must be there, even if the list is empty!
Bo Persson