Why can't I use =default for default ctors with a member initializer listWhy can't variables be declared in a switch statement?C++11 allows in-class initialization of non-static and non-const members. What changed?defaulted ctor differences between gcc 4.6 and 4.7Default, value and zero initialization messDefault initialization of class data members in C++11MSVC2015 initializes class member that should be left uninitializedCould a class type with deleted default constructor be default initialized?Enum Class Default InitializationWhy is a member not getting zero-initialized in this example?std::vector not initialized by default ctor

Multi tool use
Multi tool use

Can there be an UN resolution to remove a country from the UNSC?

What is "industrial ethernet"?

Swapping rooks in a 4x4 board

What exactly is the 'online' in OLAP and OLTP?

How to model a twisted cylinder like this

Unusual mail headers, evidence of an attempted attack. Have I been pwned?

Is it illegal to withhold someone's passport and green card in California?

How would modern naval warfare have to have developed differently for battleships to still be relevant in the 21st century?

What does the hyphen "-" mean in "tar xzf -"?

Has there been any indication at all that further negotiation between the UK and EU is possible?

Why did pressing the joystick button spit out keypresses?

Parameterize chained calls to a utility program in Bash

How large would a mega structure have to be to host 1 billion people indefinitely?

Why don't countries like Japan just print more money?

How many people are necessary to maintain modern civilisation?

If I wouldn't want to read the story, is writing it still a good idea?

What is the legal status of travelling with methadone in your carry-on?

NSE Numerical IQ Test no.12: 759802, 358829, 847123,?

Why do some professors with PhDs leave their professorships to teach high school?

Why do all the teams that I have worked with always finish a sprint without completion of all the stories?

What happens to Cessna electric flaps that are moving when power is lost?

What can I do with a research project that is my university’s intellectual property?

Drawing people along with x and y axis

Why use cross notes in sheet music for hip hop tracks?



Why can't I use =default for default ctors with a member initializer list


Why can't variables be declared in a switch statement?C++11 allows in-class initialization of non-static and non-const members. What changed?defaulted ctor differences between gcc 4.6 and 4.7Default, value and zero initialization messDefault initialization of class data members in C++11MSVC2015 initializes class member that should be left uninitializedCould a class type with deleted default constructor be default initialized?Enum Class Default InitializationWhy is a member not getting zero-initialized in this example?std::vector not initialized by default ctor






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








8















Consider the following class:



class Foo 
int a, b;
public:
Foo() : a1, b2 // Default ctor with member initializer list
//Foo() : a1, b2 = default; // Does not work but why?
;


(Edit: because it was mentioned in a couple of answers - I'm aware of in-class member initializiers, but that's not the point here)



I think the second ctor definition would be more elegant and fit better into modern C++ code (see also why you should use =default if you have to be explicit about using the default semantics). However, no common compiler seems to accept it. And cppreference is silent about it.



My first thought was that a member initializer list in a way changes the "default semantics" as explained in the linked FAQ, because it may or may not default-construct members. But then we would have the same problem for in-class initializers, just that here Foo() = default; works just fine.



So, why is it disallowed?










share|improve this question



















  • 5





    As soon as you've defined initialisers in the ctor you've provided a ctor and it's no longer the default.

    – Jonathan Potter
    Jun 5 at 12:38






  • 2





    Because "Default ctor with member initializer list" is not a default ctor. You can use inline initialization with "=default" though.

    – Steve
    Jun 5 at 12:38






  • 1





    @Quimby that's not an argument, since this is always the case. Also that's not the reason for =default, see also the referenced C++ FAQ

    – andreee
    Jun 5 at 12:40







  • 2





    Could you explain what you would expect it to mean?

    – molbdnilo
    Jun 5 at 12:42






  • 2





    Indeed, and =default accomplish different things. is generally not what you want as it kills implicitly generated default move constructor/operator.

    – ssteinberg
    Jun 5 at 12:45

















8















Consider the following class:



class Foo 
int a, b;
public:
Foo() : a1, b2 // Default ctor with member initializer list
//Foo() : a1, b2 = default; // Does not work but why?
;


(Edit: because it was mentioned in a couple of answers - I'm aware of in-class member initializiers, but that's not the point here)



I think the second ctor definition would be more elegant and fit better into modern C++ code (see also why you should use =default if you have to be explicit about using the default semantics). However, no common compiler seems to accept it. And cppreference is silent about it.



My first thought was that a member initializer list in a way changes the "default semantics" as explained in the linked FAQ, because it may or may not default-construct members. But then we would have the same problem for in-class initializers, just that here Foo() = default; works just fine.



So, why is it disallowed?










share|improve this question



















  • 5





    As soon as you've defined initialisers in the ctor you've provided a ctor and it's no longer the default.

    – Jonathan Potter
    Jun 5 at 12:38






  • 2





    Because "Default ctor with member initializer list" is not a default ctor. You can use inline initialization with "=default" though.

    – Steve
    Jun 5 at 12:38






  • 1





    @Quimby that's not an argument, since this is always the case. Also that's not the reason for =default, see also the referenced C++ FAQ

    – andreee
    Jun 5 at 12:40







  • 2





    Could you explain what you would expect it to mean?

    – molbdnilo
    Jun 5 at 12:42






  • 2





    Indeed, and =default accomplish different things. is generally not what you want as it kills implicitly generated default move constructor/operator.

    – ssteinberg
    Jun 5 at 12:45













8












8








8








Consider the following class:



class Foo 
int a, b;
public:
Foo() : a1, b2 // Default ctor with member initializer list
//Foo() : a1, b2 = default; // Does not work but why?
;


(Edit: because it was mentioned in a couple of answers - I'm aware of in-class member initializiers, but that's not the point here)



I think the second ctor definition would be more elegant and fit better into modern C++ code (see also why you should use =default if you have to be explicit about using the default semantics). However, no common compiler seems to accept it. And cppreference is silent about it.



My first thought was that a member initializer list in a way changes the "default semantics" as explained in the linked FAQ, because it may or may not default-construct members. But then we would have the same problem for in-class initializers, just that here Foo() = default; works just fine.



So, why is it disallowed?










share|improve this question
















Consider the following class:



class Foo 
int a, b;
public:
Foo() : a1, b2 // Default ctor with member initializer list
//Foo() : a1, b2 = default; // Does not work but why?
;


(Edit: because it was mentioned in a couple of answers - I'm aware of in-class member initializiers, but that's not the point here)



I think the second ctor definition would be more elegant and fit better into modern C++ code (see also why you should use =default if you have to be explicit about using the default semantics). However, no common compiler seems to accept it. And cppreference is silent about it.



My first thought was that a member initializer list in a way changes the "default semantics" as explained in the linked FAQ, because it may or may not default-construct members. But then we would have the same problem for in-class initializers, just that here Foo() = default; works just fine.



So, why is it disallowed?







c++ c++11 language-lawyer default-constructor ctor-initializer






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jun 5 at 12:54







andreee

















asked Jun 5 at 12:35









andreeeandreee

2,2341227




2,2341227







  • 5





    As soon as you've defined initialisers in the ctor you've provided a ctor and it's no longer the default.

    – Jonathan Potter
    Jun 5 at 12:38






  • 2





    Because "Default ctor with member initializer list" is not a default ctor. You can use inline initialization with "=default" though.

    – Steve
    Jun 5 at 12:38






  • 1





    @Quimby that's not an argument, since this is always the case. Also that's not the reason for =default, see also the referenced C++ FAQ

    – andreee
    Jun 5 at 12:40







  • 2





    Could you explain what you would expect it to mean?

    – molbdnilo
    Jun 5 at 12:42






  • 2





    Indeed, and =default accomplish different things. is generally not what you want as it kills implicitly generated default move constructor/operator.

    – ssteinberg
    Jun 5 at 12:45












  • 5





    As soon as you've defined initialisers in the ctor you've provided a ctor and it's no longer the default.

    – Jonathan Potter
    Jun 5 at 12:38






  • 2





    Because "Default ctor with member initializer list" is not a default ctor. You can use inline initialization with "=default" though.

    – Steve
    Jun 5 at 12:38






  • 1





    @Quimby that's not an argument, since this is always the case. Also that's not the reason for =default, see also the referenced C++ FAQ

    – andreee
    Jun 5 at 12:40







  • 2





    Could you explain what you would expect it to mean?

    – molbdnilo
    Jun 5 at 12:42






  • 2





    Indeed, and =default accomplish different things. is generally not what you want as it kills implicitly generated default move constructor/operator.

    – ssteinberg
    Jun 5 at 12:45







5




5





As soon as you've defined initialisers in the ctor you've provided a ctor and it's no longer the default.

– Jonathan Potter
Jun 5 at 12:38





As soon as you've defined initialisers in the ctor you've provided a ctor and it's no longer the default.

– Jonathan Potter
Jun 5 at 12:38




2




2





Because "Default ctor with member initializer list" is not a default ctor. You can use inline initialization with "=default" though.

– Steve
Jun 5 at 12:38





Because "Default ctor with member initializer list" is not a default ctor. You can use inline initialization with "=default" though.

– Steve
Jun 5 at 12:38




1




1





@Quimby that's not an argument, since this is always the case. Also that's not the reason for =default, see also the referenced C++ FAQ

– andreee
Jun 5 at 12:40






@Quimby that's not an argument, since this is always the case. Also that's not the reason for =default, see also the referenced C++ FAQ

– andreee
Jun 5 at 12:40





2




2





Could you explain what you would expect it to mean?

– molbdnilo
Jun 5 at 12:42





Could you explain what you would expect it to mean?

– molbdnilo
Jun 5 at 12:42




2




2





Indeed, and =default accomplish different things. is generally not what you want as it kills implicitly generated default move constructor/operator.

– ssteinberg
Jun 5 at 12:45





Indeed, and =default accomplish different things. is generally not what you want as it kills implicitly generated default move constructor/operator.

– ssteinberg
Jun 5 at 12:45












4 Answers
4






active

oldest

votes


















11














= default; is an entire definition all on its own. It's enforced, first and foremost, grammatically:




[dcl.fct.def.general]



1 Function definitions have the form



function-definition:
attribute-specifier-seqopt decl-specifier-seqopt declarator virt-specifier-seqopt function-body

function-body:
ctor-initializeropt compound-statement
function-try-block
= default ;
= delete ;



So it's either a member initializer list with a compound statement, or just plain = default;, no mishmash.



Furthermore, = default means something specific about how each member is initialized. It means we explicitly want to initialize everything like a compiler provided constructor would. That is in contradiction to "doing something special" with the members in the constructor's member initializer list.






share|improve this answer

























  • Regarding your last paragraph: What about in-class member initializers then? defining int a = 1; int b = 2 in the class and using Foo() = default; works just fine. Wouldn't that be a contradiction?

    – andreee
    Jun 5 at 12:48







  • 4





    @andreee - No. Because if you omit Foo() = default, the default member initializers are still in effect. That is what the compiler provided constructor will do.

    – StoryTeller
    Jun 5 at 12:48












  • Thanks, that makes sense now. I also liked @NathanOliver's answer a lot, but I like this one slightly better (and you cannot accept two questions :-)).

    – andreee
    Jun 5 at 13:16


















7














Doing a1, b2 means you no longer can specify it as default. A default function per [dcl.fct.def.default]/1 is defined as




A function definition whose function-body is of the form = default; is called an explicitly-defaulted definition.




And if we check what a function-body is in [dcl.fct.def.general]/1 we see that it contains a ctor-initializer which is a mem-initializer-list



This means you can't initialize members if you want a default definition provided by the compiler.



What you can do to work around this is to specify the default values in the class directly, and then declare the constructor as default like



class Foo 
int a1, b2;
public:
Foo() = default;

;





share|improve this answer
































    3














    This doesn't directly answer the question, however it is the c++ "way" is to use the default member initializer instead, that it



    class Foo 
    int a = 1, b = 2;
    public:
    Foo() = default;
    ;


    The syntax you purpose is simply not a default, per se, constructor anymore.






    share|improve this answer

























    • Thanks, but as mentioned in my question, this is not what I was interested in.

      – andreee
      Jun 5 at 13:18



















    2














    It's disallowed because what you're trying to do by definition means it's no longer a default constructor. And there's a more elegant way of accomplishing what you want anyway:



    class Foo 
    int a 1;
    int b 2;
    public:
    Foo() = default;
    ;





    share|improve this answer























    • Thanks, but as mentioned in my question, this is not what I was interested in.

      – andreee
      Jun 5 at 13:18











    • You mean, as you mentioned in an edit to your question after this answer had been posted?

      – Steve
      Jun 5 at 13:19











    • Yes. But I also mentioned in-class initializers in my original post and that it doesn't pose a problem there (second last paragraph). That was just a remark, no offense :-)

      – andreee
      Jun 5 at 13:20







    • 1





      a default constructor is by definition one that can be called with no arguments. see here en.cppreference.com/w/cpp/language/default_constructor

      – formerlyknownas_463035818
      Jun 5 at 13:37













    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f56460611%2fwhy-cant-i-use-default-for-default-ctors-with-a-member-initializer-list%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    4 Answers
    4






    active

    oldest

    votes








    4 Answers
    4






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    11














    = default; is an entire definition all on its own. It's enforced, first and foremost, grammatically:




    [dcl.fct.def.general]



    1 Function definitions have the form



    function-definition:
    attribute-specifier-seqopt decl-specifier-seqopt declarator virt-specifier-seqopt function-body

    function-body:
    ctor-initializeropt compound-statement
    function-try-block
    = default ;
    = delete ;



    So it's either a member initializer list with a compound statement, or just plain = default;, no mishmash.



    Furthermore, = default means something specific about how each member is initialized. It means we explicitly want to initialize everything like a compiler provided constructor would. That is in contradiction to "doing something special" with the members in the constructor's member initializer list.






    share|improve this answer

























    • Regarding your last paragraph: What about in-class member initializers then? defining int a = 1; int b = 2 in the class and using Foo() = default; works just fine. Wouldn't that be a contradiction?

      – andreee
      Jun 5 at 12:48







    • 4





      @andreee - No. Because if you omit Foo() = default, the default member initializers are still in effect. That is what the compiler provided constructor will do.

      – StoryTeller
      Jun 5 at 12:48












    • Thanks, that makes sense now. I also liked @NathanOliver's answer a lot, but I like this one slightly better (and you cannot accept two questions :-)).

      – andreee
      Jun 5 at 13:16















    11














    = default; is an entire definition all on its own. It's enforced, first and foremost, grammatically:




    [dcl.fct.def.general]



    1 Function definitions have the form



    function-definition:
    attribute-specifier-seqopt decl-specifier-seqopt declarator virt-specifier-seqopt function-body

    function-body:
    ctor-initializeropt compound-statement
    function-try-block
    = default ;
    = delete ;



    So it's either a member initializer list with a compound statement, or just plain = default;, no mishmash.



    Furthermore, = default means something specific about how each member is initialized. It means we explicitly want to initialize everything like a compiler provided constructor would. That is in contradiction to "doing something special" with the members in the constructor's member initializer list.






    share|improve this answer

























    • Regarding your last paragraph: What about in-class member initializers then? defining int a = 1; int b = 2 in the class and using Foo() = default; works just fine. Wouldn't that be a contradiction?

      – andreee
      Jun 5 at 12:48







    • 4





      @andreee - No. Because if you omit Foo() = default, the default member initializers are still in effect. That is what the compiler provided constructor will do.

      – StoryTeller
      Jun 5 at 12:48












    • Thanks, that makes sense now. I also liked @NathanOliver's answer a lot, but I like this one slightly better (and you cannot accept two questions :-)).

      – andreee
      Jun 5 at 13:16













    11












    11








    11







    = default; is an entire definition all on its own. It's enforced, first and foremost, grammatically:




    [dcl.fct.def.general]



    1 Function definitions have the form



    function-definition:
    attribute-specifier-seqopt decl-specifier-seqopt declarator virt-specifier-seqopt function-body

    function-body:
    ctor-initializeropt compound-statement
    function-try-block
    = default ;
    = delete ;



    So it's either a member initializer list with a compound statement, or just plain = default;, no mishmash.



    Furthermore, = default means something specific about how each member is initialized. It means we explicitly want to initialize everything like a compiler provided constructor would. That is in contradiction to "doing something special" with the members in the constructor's member initializer list.






    share|improve this answer















    = default; is an entire definition all on its own. It's enforced, first and foremost, grammatically:




    [dcl.fct.def.general]



    1 Function definitions have the form



    function-definition:
    attribute-specifier-seqopt decl-specifier-seqopt declarator virt-specifier-seqopt function-body

    function-body:
    ctor-initializeropt compound-statement
    function-try-block
    = default ;
    = delete ;



    So it's either a member initializer list with a compound statement, or just plain = default;, no mishmash.



    Furthermore, = default means something specific about how each member is initialized. It means we explicitly want to initialize everything like a compiler provided constructor would. That is in contradiction to "doing something special" with the members in the constructor's member initializer list.







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Jun 5 at 12:50

























    answered Jun 5 at 12:43









    StoryTellerStoryTeller

    112k18239303




    112k18239303












    • Regarding your last paragraph: What about in-class member initializers then? defining int a = 1; int b = 2 in the class and using Foo() = default; works just fine. Wouldn't that be a contradiction?

      – andreee
      Jun 5 at 12:48







    • 4





      @andreee - No. Because if you omit Foo() = default, the default member initializers are still in effect. That is what the compiler provided constructor will do.

      – StoryTeller
      Jun 5 at 12:48












    • Thanks, that makes sense now. I also liked @NathanOliver's answer a lot, but I like this one slightly better (and you cannot accept two questions :-)).

      – andreee
      Jun 5 at 13:16

















    • Regarding your last paragraph: What about in-class member initializers then? defining int a = 1; int b = 2 in the class and using Foo() = default; works just fine. Wouldn't that be a contradiction?

      – andreee
      Jun 5 at 12:48







    • 4





      @andreee - No. Because if you omit Foo() = default, the default member initializers are still in effect. That is what the compiler provided constructor will do.

      – StoryTeller
      Jun 5 at 12:48












    • Thanks, that makes sense now. I also liked @NathanOliver's answer a lot, but I like this one slightly better (and you cannot accept two questions :-)).

      – andreee
      Jun 5 at 13:16
















    Regarding your last paragraph: What about in-class member initializers then? defining int a = 1; int b = 2 in the class and using Foo() = default; works just fine. Wouldn't that be a contradiction?

    – andreee
    Jun 5 at 12:48






    Regarding your last paragraph: What about in-class member initializers then? defining int a = 1; int b = 2 in the class and using Foo() = default; works just fine. Wouldn't that be a contradiction?

    – andreee
    Jun 5 at 12:48





    4




    4





    @andreee - No. Because if you omit Foo() = default, the default member initializers are still in effect. That is what the compiler provided constructor will do.

    – StoryTeller
    Jun 5 at 12:48






    @andreee - No. Because if you omit Foo() = default, the default member initializers are still in effect. That is what the compiler provided constructor will do.

    – StoryTeller
    Jun 5 at 12:48














    Thanks, that makes sense now. I also liked @NathanOliver's answer a lot, but I like this one slightly better (and you cannot accept two questions :-)).

    – andreee
    Jun 5 at 13:16





    Thanks, that makes sense now. I also liked @NathanOliver's answer a lot, but I like this one slightly better (and you cannot accept two questions :-)).

    – andreee
    Jun 5 at 13:16













    7














    Doing a1, b2 means you no longer can specify it as default. A default function per [dcl.fct.def.default]/1 is defined as




    A function definition whose function-body is of the form = default; is called an explicitly-defaulted definition.




    And if we check what a function-body is in [dcl.fct.def.general]/1 we see that it contains a ctor-initializer which is a mem-initializer-list



    This means you can't initialize members if you want a default definition provided by the compiler.



    What you can do to work around this is to specify the default values in the class directly, and then declare the constructor as default like



    class Foo 
    int a1, b2;
    public:
    Foo() = default;

    ;





    share|improve this answer





























      7














      Doing a1, b2 means you no longer can specify it as default. A default function per [dcl.fct.def.default]/1 is defined as




      A function definition whose function-body is of the form = default; is called an explicitly-defaulted definition.




      And if we check what a function-body is in [dcl.fct.def.general]/1 we see that it contains a ctor-initializer which is a mem-initializer-list



      This means you can't initialize members if you want a default definition provided by the compiler.



      What you can do to work around this is to specify the default values in the class directly, and then declare the constructor as default like



      class Foo 
      int a1, b2;
      public:
      Foo() = default;

      ;





      share|improve this answer



























        7












        7








        7







        Doing a1, b2 means you no longer can specify it as default. A default function per [dcl.fct.def.default]/1 is defined as




        A function definition whose function-body is of the form = default; is called an explicitly-defaulted definition.




        And if we check what a function-body is in [dcl.fct.def.general]/1 we see that it contains a ctor-initializer which is a mem-initializer-list



        This means you can't initialize members if you want a default definition provided by the compiler.



        What you can do to work around this is to specify the default values in the class directly, and then declare the constructor as default like



        class Foo 
        int a1, b2;
        public:
        Foo() = default;

        ;





        share|improve this answer















        Doing a1, b2 means you no longer can specify it as default. A default function per [dcl.fct.def.default]/1 is defined as




        A function definition whose function-body is of the form = default; is called an explicitly-defaulted definition.




        And if we check what a function-body is in [dcl.fct.def.general]/1 we see that it contains a ctor-initializer which is a mem-initializer-list



        This means you can't initialize members if you want a default definition provided by the compiler.



        What you can do to work around this is to specify the default values in the class directly, and then declare the constructor as default like



        class Foo 
        int a1, b2;
        public:
        Foo() = default;

        ;






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Jun 5 at 18:39









        René Richter

        2,56012235




        2,56012235










        answered Jun 5 at 12:51









        NathanOliverNathanOliver

        105k19155231




        105k19155231





















            3














            This doesn't directly answer the question, however it is the c++ "way" is to use the default member initializer instead, that it



            class Foo 
            int a = 1, b = 2;
            public:
            Foo() = default;
            ;


            The syntax you purpose is simply not a default, per se, constructor anymore.






            share|improve this answer

























            • Thanks, but as mentioned in my question, this is not what I was interested in.

              – andreee
              Jun 5 at 13:18
















            3














            This doesn't directly answer the question, however it is the c++ "way" is to use the default member initializer instead, that it



            class Foo 
            int a = 1, b = 2;
            public:
            Foo() = default;
            ;


            The syntax you purpose is simply not a default, per se, constructor anymore.






            share|improve this answer

























            • Thanks, but as mentioned in my question, this is not what I was interested in.

              – andreee
              Jun 5 at 13:18














            3












            3








            3







            This doesn't directly answer the question, however it is the c++ "way" is to use the default member initializer instead, that it



            class Foo 
            int a = 1, b = 2;
            public:
            Foo() = default;
            ;


            The syntax you purpose is simply not a default, per se, constructor anymore.






            share|improve this answer















            This doesn't directly answer the question, however it is the c++ "way" is to use the default member initializer instead, that it



            class Foo 
            int a = 1, b = 2;
            public:
            Foo() = default;
            ;


            The syntax you purpose is simply not a default, per se, constructor anymore.







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Jun 5 at 13:09

























            answered Jun 5 at 12:44









            ssteinbergssteinberg

            5,51033059




            5,51033059












            • Thanks, but as mentioned in my question, this is not what I was interested in.

              – andreee
              Jun 5 at 13:18


















            • Thanks, but as mentioned in my question, this is not what I was interested in.

              – andreee
              Jun 5 at 13:18

















            Thanks, but as mentioned in my question, this is not what I was interested in.

            – andreee
            Jun 5 at 13:18






            Thanks, but as mentioned in my question, this is not what I was interested in.

            – andreee
            Jun 5 at 13:18












            2














            It's disallowed because what you're trying to do by definition means it's no longer a default constructor. And there's a more elegant way of accomplishing what you want anyway:



            class Foo 
            int a 1;
            int b 2;
            public:
            Foo() = default;
            ;





            share|improve this answer























            • Thanks, but as mentioned in my question, this is not what I was interested in.

              – andreee
              Jun 5 at 13:18











            • You mean, as you mentioned in an edit to your question after this answer had been posted?

              – Steve
              Jun 5 at 13:19











            • Yes. But I also mentioned in-class initializers in my original post and that it doesn't pose a problem there (second last paragraph). That was just a remark, no offense :-)

              – andreee
              Jun 5 at 13:20







            • 1





              a default constructor is by definition one that can be called with no arguments. see here en.cppreference.com/w/cpp/language/default_constructor

              – formerlyknownas_463035818
              Jun 5 at 13:37















            2














            It's disallowed because what you're trying to do by definition means it's no longer a default constructor. And there's a more elegant way of accomplishing what you want anyway:



            class Foo 
            int a 1;
            int b 2;
            public:
            Foo() = default;
            ;





            share|improve this answer























            • Thanks, but as mentioned in my question, this is not what I was interested in.

              – andreee
              Jun 5 at 13:18











            • You mean, as you mentioned in an edit to your question after this answer had been posted?

              – Steve
              Jun 5 at 13:19











            • Yes. But I also mentioned in-class initializers in my original post and that it doesn't pose a problem there (second last paragraph). That was just a remark, no offense :-)

              – andreee
              Jun 5 at 13:20







            • 1





              a default constructor is by definition one that can be called with no arguments. see here en.cppreference.com/w/cpp/language/default_constructor

              – formerlyknownas_463035818
              Jun 5 at 13:37













            2












            2








            2







            It's disallowed because what you're trying to do by definition means it's no longer a default constructor. And there's a more elegant way of accomplishing what you want anyway:



            class Foo 
            int a 1;
            int b 2;
            public:
            Foo() = default;
            ;





            share|improve this answer













            It's disallowed because what you're trying to do by definition means it's no longer a default constructor. And there's a more elegant way of accomplishing what you want anyway:



            class Foo 
            int a 1;
            int b 2;
            public:
            Foo() = default;
            ;






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Jun 5 at 12:43









            SteveSteve

            1,752618




            1,752618












            • Thanks, but as mentioned in my question, this is not what I was interested in.

              – andreee
              Jun 5 at 13:18











            • You mean, as you mentioned in an edit to your question after this answer had been posted?

              – Steve
              Jun 5 at 13:19











            • Yes. But I also mentioned in-class initializers in my original post and that it doesn't pose a problem there (second last paragraph). That was just a remark, no offense :-)

              – andreee
              Jun 5 at 13:20







            • 1





              a default constructor is by definition one that can be called with no arguments. see here en.cppreference.com/w/cpp/language/default_constructor

              – formerlyknownas_463035818
              Jun 5 at 13:37

















            • Thanks, but as mentioned in my question, this is not what I was interested in.

              – andreee
              Jun 5 at 13:18











            • You mean, as you mentioned in an edit to your question after this answer had been posted?

              – Steve
              Jun 5 at 13:19











            • Yes. But I also mentioned in-class initializers in my original post and that it doesn't pose a problem there (second last paragraph). That was just a remark, no offense :-)

              – andreee
              Jun 5 at 13:20







            • 1





              a default constructor is by definition one that can be called with no arguments. see here en.cppreference.com/w/cpp/language/default_constructor

              – formerlyknownas_463035818
              Jun 5 at 13:37
















            Thanks, but as mentioned in my question, this is not what I was interested in.

            – andreee
            Jun 5 at 13:18





            Thanks, but as mentioned in my question, this is not what I was interested in.

            – andreee
            Jun 5 at 13:18













            You mean, as you mentioned in an edit to your question after this answer had been posted?

            – Steve
            Jun 5 at 13:19





            You mean, as you mentioned in an edit to your question after this answer had been posted?

            – Steve
            Jun 5 at 13:19













            Yes. But I also mentioned in-class initializers in my original post and that it doesn't pose a problem there (second last paragraph). That was just a remark, no offense :-)

            – andreee
            Jun 5 at 13:20






            Yes. But I also mentioned in-class initializers in my original post and that it doesn't pose a problem there (second last paragraph). That was just a remark, no offense :-)

            – andreee
            Jun 5 at 13:20





            1




            1





            a default constructor is by definition one that can be called with no arguments. see here en.cppreference.com/w/cpp/language/default_constructor

            – formerlyknownas_463035818
            Jun 5 at 13:37





            a default constructor is by definition one that can be called with no arguments. see here en.cppreference.com/w/cpp/language/default_constructor

            – formerlyknownas_463035818
            Jun 5 at 13:37

















            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f56460611%2fwhy-cant-i-use-default-for-default-ctors-with-a-member-initializer-list%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            2 IQx,2Sq
            TzUGUX,O93zQcZz8tRI4lpP,kPoEgk8jym rCSOalZh1z65hMkv1sfj43eC7Cu,yhF6 qSc5PRdyi0Ypev 2cmr1IwP

            Popular posts from this blog

            RemoteApp sporadic failureWindows 2008 RemoteAPP client disconnects within a matter of minutesWhat is the minimum version of RDP supported by Server 2012 RDS?How to configure a Remoteapp server to increase stabilityMicrosoft RemoteApp Active SessionRDWeb TS connection broken for some users post RemoteApp certificate changeRemote Desktop Licensing, RemoteAPPRDS 2012 R2 some users are not able to logon after changed date and time on Connection BrokersWhat happens during Remote Desktop logon, and is there any logging?After installing RDS on WinServer 2016 I still can only connect with two users?RD Connection via RDGW to Session host is not connecting

            Vilaño, A Laracha Índice Patrimonio | Lugares e parroquias | Véxase tamén | Menú de navegación43°14′52″N 8°36′03″O / 43.24775, -8.60070

            Cegueira Índice Epidemioloxía | Deficiencia visual | Tipos de cegueira | Principais causas de cegueira | Tratamento | Técnicas de adaptación e axudas | Vida dos cegos | Primeiros auxilios | Crenzas respecto das persoas cegas | Crenzas das persoas cegas | O neno deficiente visual | Aspectos psicolóxicos da cegueira | Notas | Véxase tamén | Menú de navegación54.054.154.436928256blindnessDicionario da Real Academia GalegaPortal das Palabras"International Standards: Visual Standards — Aspects and Ranges of Vision Loss with Emphasis on Population Surveys.""Visual impairment and blindness""Presentan un plan para previr a cegueira"o orixinalACCDV Associació Catalana de Cecs i Disminuïts Visuals - PMFTrachoma"Effect of gene therapy on visual function in Leber's congenital amaurosis"1844137110.1056/NEJMoa0802268Cans guía - os mellores amigos dos cegosArquivadoEscola de cans guía para cegos en Mortágua, PortugalArquivado"Tecnología para ciegos y deficientes visuales. Recopilación de recursos gratuitos en la Red""Colorino""‘COL.diesis’, escuchar los sonidos del color""COL.diesis: Transforming Colour into Melody and Implementing the Result in a Colour Sensor Device"o orixinal"Sistema de desarrollo de sinestesia color-sonido para invidentes utilizando un protocolo de audio""Enseñanza táctil - geometría y color. Juegos didácticos para niños ciegos y videntes""Sistema Constanz"L'ocupació laboral dels cecs a l'Estat espanyol està pràcticament equiparada a la de les persones amb visió, entrevista amb Pedro ZuritaONCE (Organización Nacional de Cegos de España)Prevención da cegueiraDescrición de deficiencias visuais (Disc@pnet)Braillín, un boneco atractivo para calquera neno, con ou sen discapacidade, que permite familiarizarse co sistema de escritura e lectura brailleAxudas Técnicas36838ID00897494007150-90057129528256DOID:1432HP:0000618D001766C10.597.751.941.162C97109C0155020