• Initialization of data members inside a class

    From Joe Bentley@21:1/5 to All on Sun Feb 21 13:20:11 2016
    Is it permissible to initialize non-static data members inside a class,
    like so?

    class whatever
    {
    int x = 9;
    const int y = 10;
    ...
    };

    If so, is there a reference in the "standard" that grants this
    permission, and when did this syntax come about?

    Thanks


    --
    [ See http://www.gotw.ca/resources/clcm.htm for info about ]
    [ comp.lang.c++.moderated. First time posters: Do this! ]

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Norbert_Paul@21:1/5 to Joe Bentley on Mon Feb 22 06:47:37 2016
    Assuming that
    http://en.cppreference.com/w/cpp/language/class#Member_specification
    is consistent with the standard, I'd say yes.

    Norbert

    Joe Bentley wrote:

    Is it permissible to initialize non-static data members inside a class,
    like so?

    class whatever
    {
    int x = 9;
    const int y = 10;
    ...
    };

    If so, is there a reference in the "standard" that grants this
    permission, and when did this syntax come about?

    Thanks


    --
    [ See http://www.gotw.ca/resources/clcm.htm for info about ]
    [ comp.lang.c++.moderated. First time posters: Do this! ]

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Richard@21:1/5 to All on Mon Feb 22 14:26:17 2016
    [Please do not mail me a copy of your followup]

    Joe Bentley <joe.foxhound@googlemail.com> spake the secret code <a8d71d07-329c-41de-a5ff-ff5a06e3017d@googlegroups.com> thusly:

    Is it permissible to initialize non-static data members inside a class,
    like so?

    class whatever
    {
    int x = 9;
    const int y = 10;
    ...
    };

    Yes

    If so, is there a reference in the "standard" that grants this
    permission, and when did this syntax come about?

    This was introduced in C++11.

    See <http://en.cppreference.com/w/cpp/language/data_members> for C++11
    and C++14 specific discussion on member initialization.
    --
    "The Direct3D Graphics Pipeline" free book <http://tinyurl.com/d3d-pipeline>
    The Computer Graphics Museum <http://computergraphicsmuseum.org>
    The Terminals Wiki <http://terminals.classiccmp.org>
    Legalize Adulthood! (my blog) <http://legalizeadulthood.wordpress.com>


    [ See http://www.gotw.ca/resources/clcm.htm for info about ]
    [ comp.lang.c++.moderated. First time posters: Do this! ]

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)