Topic: Question on syntax of member function declarations


Author: cohenb@mossback.slc.com (Bruce Cohen)
Date: 12 Nov 93 20:22:15 GMT
Raw View
In Section 17.5, "Class Declarations", the ARM states that member
functions are defined inside a class declarations as follows:

    member-declaration:
        ...
        function-definition ;opt
        ...

    function-definition:
        decl-specifiers opt declarator ctor-initializer opt fct-body

which I take to imply that the following two member function defintions
are valid syntax within a class declaration and are completely
equivalent:

    class classDecl1 {
        int fct(int i) { return i; }
    };

and
    class classDecl2 {
        int fct(int i) { return i; } ;
    };

Was this example intended behavior, and is the grammar still defined
that way in the standard working document?  It's not a completely
academic question: I am doing some maintenance on a C++ code
preprocessor which currently doesn't like classDecl2, and it will take
some effort, because of side-effects of the implementation, to make it
accept both.

Thanks,
--
-----------------------------------------------------------------------------
Rebuttal to Keynes:  In the long run, our children are alive.
-----------------------------------------------------------------------------
Bruce Cohen, Servio Corporation                  |   email:  cohenb@slc.com
15400 NW Greenbrier Pkwy, Suite 280              |   phone: (503)690-3602
Beaverton, OR USA 97006                          |   fax: (503)629-8556




Author: kanze@us-es.sel.de (James Kanze)
Date: 15 Nov 93 15:01:13
Raw View
In article <COHENB.93Nov12122215@mossback.slc.com>
cohenb@mossback.slc.com (Bruce Cohen) writes:

|> In Section 17.5, "Class Declarations", the ARM states that member
|> functions are defined inside a class declarations as follows:

|>     member-declaration:
|>         ...
|>         function-definition ;opt
|>         ...

|>     function-definition:
|>         decl-specifiers opt declarator ctor-initializer opt fct-body

|> which I take to imply that the following two member function defintions
|> are valid syntax within a class declaration and are completely
|> equivalent:

|>     class classDecl1 {
|>         int fct(int i) { return i; }
|>     };

|> and
|>     class classDecl2 {
|>         int fct(int i) { return i; } ;
|>     };

|> Was this example intended behavior, and is the grammar still defined
|> that way in the standard working document?

Yes, and yes.

I believe having heard Bjarne explain that he allowed both
intentionally, as he was always making a mistake about using a ';' or
not himself.
--
James Kanze                             email: kanze@us-es.sel.de
GABI Software, Sarl., 8 rue du Faisan, F-67000 Strasbourg, France
Conseils en informatique industrielle --
                   -- Beratung in industrieller Datenverarbeitung