On May 22, 4:38 pm, Rolf Magnus <ramag...@t-online.dewrote:
Quote:
Victor Bazarov wrote:
Quote:
stonny wrote:
Quote:
Sorry about the beginners question
Quote:
Quote:
Quote:
In the header file, each time you define a class or
function, it has to be followed by a semicolon. But in the
source file, the functions do not have to be followed by
semicolon.
Quote:
Quote:
No. There should be no semicolons after a function body
anywhere. Inside a class definition you're allowed to put
extraneous semicolons but you do not have to put them there.
Actually, I find the practice of placing a semicolon after
the body of a function defined inside a class definition,
irritating.
Quote:
However, I can see how it can be a bit hard to understand
where to put semicolons and why. Take this example:
Quote:
namespace N
{
class C
{
void f()
{
} // (1)
>
}; // (2)
Quote:
void f()
{
} // (3)
} // (4)
Quote:
At (1) you can choose whether to add a semicolon or not
At (2) you must put one
At (3) and (4), it's forbidden
Quote:
Especially the difference between (1) and (3) is surprising.
But historically explainable: (3) is according to C; in the case
of (1), Stroustrup felt that this distinction was artificial,
and added an optional semicolon to the grammar.
IMHO, the simplest solution would just be to modify the grammar
so that an empty statement is a declaration, rather than an
expression statement, so that a semicolon may appear anywhere a
declaration may, rather than only where an expression statement
is allowed. Or simply say that an empty statement is an empty
statement (a new type of statement), and that it can occur
anywhere any other statement may occur.
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34