On Tue, 01 Jun 2004 00:51:15 GMT, cppaddict <he***@hello.com> wrote:
It struck me as odd today that while class definitions require a
semi-colon at the end, function definitions do not. I was curious if
this small syntactic difference represents a larger conceptual
difference between these two language constructs.
I know that a semi-colon is used to "end a statement," but why would a
function definition not be considered a statement, while a class def
is?
If there is a larger conceptual difference (other than the
unilluminating fact that one is a function and one a class), can
anyone explain what it is?
Thanks,
cpp
Thore's reason works for me...but there's also this: The C++ Standard
defines the syntax of a function definition (8.4/1) as follows:
Function definitions have the form
function-definition:
decl-specifier-seqopt declarator ctor-initializeropt function-body
decl-specifier-seqopt declarator function-try-block
function-body:
compound-statement
Note the final "compound-statement". Compound statements don't end in
semi-colons! And the compound statement "part" of a function definition
(the "function-body") isn't the entire function definition; that's why a
function definition is "not considered a statement".
-leor
--
Leor Zolman --- BD Software ---
www.bdsoft.com
On-Site Training in C/C++, Java, Perl and Unix
C++ users: download BD Software's free STL Error Message Decryptor at:
www.bdsoft.com/tools/stlfilt.html