Why doesn't my compiler recognise “Bond() = default;”?











up vote
33
down vote

favorite












Please look at this code



class Bond
{
public:
Bond(int payments_per_year, int period_lengths_in_months);
Bond() = default;

private:
const int payments_per_year;
const int period_length_in_months;
};

int main()
{
Bond b; // Error here
}


When attempting to compile I get an error:




error C2280: 'Bond::Bond(void)': attempting to reference a deleted function".




It's not a "rule of 3" violation since I've added the default constructor back.



Why doesn't the compiler recognise Bond() = default;?










share|improve this question




















  • 2




    I have other error uninitialized const member in 'const int'. When you initialize constant member no more error produced.
    – serge
    Nov 9 at 12:14






  • 2




    Rule of three violation has got nothing to do with the problem at all, regardless of the presence of a (default) constructor.
    – Konrad Rudolph
    Nov 9 at 15:04






  • 2




    = defaulting a special member doesn't mean that it exists, but that the implicit one is generated. If the implicitly generated one doesn't exist, then you get this.
    – Rakete1111
    Nov 9 at 15:06






  • 4




    Even though we are quite likely to recognize the compiler from the error cited in this case, any question with "why my compiler" would benefit greatly from indicating which compiler, and which version of it.
    – Matthieu M.
    Nov 9 at 20:19















up vote
33
down vote

favorite












Please look at this code



class Bond
{
public:
Bond(int payments_per_year, int period_lengths_in_months);
Bond() = default;

private:
const int payments_per_year;
const int period_length_in_months;
};

int main()
{
Bond b; // Error here
}


When attempting to compile I get an error:




error C2280: 'Bond::Bond(void)': attempting to reference a deleted function".




It's not a "rule of 3" violation since I've added the default constructor back.



Why doesn't the compiler recognise Bond() = default;?










share|improve this question




















  • 2




    I have other error uninitialized const member in 'const int'. When you initialize constant member no more error produced.
    – serge
    Nov 9 at 12:14






  • 2




    Rule of three violation has got nothing to do with the problem at all, regardless of the presence of a (default) constructor.
    – Konrad Rudolph
    Nov 9 at 15:04






  • 2




    = defaulting a special member doesn't mean that it exists, but that the implicit one is generated. If the implicitly generated one doesn't exist, then you get this.
    – Rakete1111
    Nov 9 at 15:06






  • 4




    Even though we are quite likely to recognize the compiler from the error cited in this case, any question with "why my compiler" would benefit greatly from indicating which compiler, and which version of it.
    – Matthieu M.
    Nov 9 at 20:19













up vote
33
down vote

favorite









up vote
33
down vote

favorite











Please look at this code



class Bond
{
public:
Bond(int payments_per_year, int period_lengths_in_months);
Bond() = default;

private:
const int payments_per_year;
const int period_length_in_months;
};

int main()
{
Bond b; // Error here
}


When attempting to compile I get an error:




error C2280: 'Bond::Bond(void)': attempting to reference a deleted function".




It's not a "rule of 3" violation since I've added the default constructor back.



Why doesn't the compiler recognise Bond() = default;?










share|improve this question















Please look at this code



class Bond
{
public:
Bond(int payments_per_year, int period_lengths_in_months);
Bond() = default;

private:
const int payments_per_year;
const int period_length_in_months;
};

int main()
{
Bond b; // Error here
}


When attempting to compile I get an error:




error C2280: 'Bond::Bond(void)': attempting to reference a deleted function".




It's not a "rule of 3" violation since I've added the default constructor back.



Why doesn't the compiler recognise Bond() = default;?







c++ c++11






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 10 at 7:01









Peter Mortensen

13.3k1983111




13.3k1983111










asked Nov 9 at 11:42









Sasidiran Sangamanautram

17827




17827








  • 2




    I have other error uninitialized const member in 'const int'. When you initialize constant member no more error produced.
    – serge
    Nov 9 at 12:14






  • 2




    Rule of three violation has got nothing to do with the problem at all, regardless of the presence of a (default) constructor.
    – Konrad Rudolph
    Nov 9 at 15:04






  • 2




    = defaulting a special member doesn't mean that it exists, but that the implicit one is generated. If the implicitly generated one doesn't exist, then you get this.
    – Rakete1111
    Nov 9 at 15:06






  • 4




    Even though we are quite likely to recognize the compiler from the error cited in this case, any question with "why my compiler" would benefit greatly from indicating which compiler, and which version of it.
    – Matthieu M.
    Nov 9 at 20:19














  • 2




    I have other error uninitialized const member in 'const int'. When you initialize constant member no more error produced.
    – serge
    Nov 9 at 12:14






  • 2




    Rule of three violation has got nothing to do with the problem at all, regardless of the presence of a (default) constructor.
    – Konrad Rudolph
    Nov 9 at 15:04






  • 2




    = defaulting a special member doesn't mean that it exists, but that the implicit one is generated. If the implicitly generated one doesn't exist, then you get this.
    – Rakete1111
    Nov 9 at 15:06






  • 4




    Even though we are quite likely to recognize the compiler from the error cited in this case, any question with "why my compiler" would benefit greatly from indicating which compiler, and which version of it.
    – Matthieu M.
    Nov 9 at 20:19








2




2




I have other error uninitialized const member in 'const int'. When you initialize constant member no more error produced.
– serge
Nov 9 at 12:14




I have other error uninitialized const member in 'const int'. When you initialize constant member no more error produced.
– serge
Nov 9 at 12:14




2




2




Rule of three violation has got nothing to do with the problem at all, regardless of the presence of a (default) constructor.
– Konrad Rudolph
Nov 9 at 15:04




Rule of three violation has got nothing to do with the problem at all, regardless of the presence of a (default) constructor.
– Konrad Rudolph
Nov 9 at 15:04




2




2




= defaulting a special member doesn't mean that it exists, but that the implicit one is generated. If the implicitly generated one doesn't exist, then you get this.
– Rakete1111
Nov 9 at 15:06




= defaulting a special member doesn't mean that it exists, but that the implicit one is generated. If the implicitly generated one doesn't exist, then you get this.
– Rakete1111
Nov 9 at 15:06




4




4




Even though we are quite likely to recognize the compiler from the error cited in this case, any question with "why my compiler" would benefit greatly from indicating which compiler, and which version of it.
– Matthieu M.
Nov 9 at 20:19




Even though we are quite likely to recognize the compiler from the error cited in this case, any question with "why my compiler" would benefit greatly from indicating which compiler, and which version of it.
– Matthieu M.
Nov 9 at 20:19












3 Answers
3






active

oldest

votes

















up vote
22
down vote



accepted










You are being affected by section [class.default.ctor]p2 of the draft C++ standard (or [class.ctor]p5 in C++11) which says:




A defaulted default constructor for class X is defined as deleted if:

...

- any non-variant non-static data member of const-qualified type (or array thereof) with no brace-or-equal-initializer does not have a user-provided default constructor,

...




They possible key to fixing your issue is with the phrase with no brace-or-equal-initializer so if you provide brace-or-equal-initializer that will fix your issue e.g.:



const int payments_per_year{12};
const int period_length_in_months{48};


brace-or-equal-initializer does not require braces, we can see this the grammar:



brace-or-equal-initializer:
= initializer-clause
braced-init-list


but using uniform initialization has some advantages such as making narrowing conversions ill-formed that it is worth getting used to using them.



Both gcc and clang provide more meaningful diagnostics for this see the live godbolt session. Sometimes it can be helpful to try your code on multiple compilers, especially if you have a minimal test case like this e.g. clang says:



 warning: explicitly defaulted default constructor is implicitly deleted [-Wdefaulted-function-deleted]
Bond() = default;
^
note: default constructor of 'Bond' is implicitly deleted because field 'payments_per_year' of const-qualified type 'const int' would not be initialized
const int payments_per_year;
^
...





share|improve this answer



















  • 1




    It may be worth filing a bug report, the diagnostic could be more meaningful.
    – Shafik Yaghmour
    Nov 9 at 14:14






  • 1




    Some examples of [uniform initialization catching bugs that came up recently](twitter.com/shafikyaghmour/status/1058737227184844800
    – Shafik Yaghmour
    Nov 9 at 18:14






  • 2




    thank you for this detail answer.
    – Sasidiran Sangamanautram
    Nov 12 at 8:27


















up vote
49
down vote













The default constructor is suppressed since there are constant members that need to be explicitly initialised.



Therefore, due to that suppression, writing Bond() = default does not reintroduce the default constructor.



(You can see this effect by removing all the constructors in the class - you still can't instantiate a b.)



If you drop the const from the members then all will be well; although another alternative is to supply a brace-or-equal-initializer for each const member;



const int payments_per_year = 2;
const int period_length_in_months = 6;


for example.






share|improve this answer






























    up vote
    23
    down vote













    Another fix, is to specify a default value in the declaration of the constants:



    const int payments_per_year = {12};


    This can still be overridden by the valued constructor, but allows the default constructor to proceed.



    This is also a very flexible way to simplify your multiple constructor cases.






    share|improve this answer

















    • 1




      Do we need the braces?
      – Paul Sanders
      Nov 9 at 14:35






    • 2




      Equals and braces is definitely weird. Not sure what it actually means. Init from an initializer_list? Anyway: in-class member initializers are – well – initializers, and the syntax rules for initialization apply. That means either = or {}.
      – besc
      Nov 9 at 14:57






    • 6




      @PaulSanders no, you don't need braces but uniform initialization has a lot of advantages such as making narrowing conversions ill-formed that it is worth getting used to using them. See my update below.
      – Shafik Yaghmour
      Nov 9 at 17:17








    • 4




      @ShafikYaghmour: You could keep the braces and drop the equal though.
      – Matthieu M.
      Nov 9 at 20:20






    • 1




      @ShafikYaghmour: Yep, and that's part of the reason why I much prefer your answer (the other being actual standard quotes).
      – Matthieu M.
      Nov 11 at 12:02











    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',
    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%2f53225106%2fwhy-doesnt-my-compiler-recognise-bond-default%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    3 Answers
    3






    active

    oldest

    votes








    3 Answers
    3






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    22
    down vote



    accepted










    You are being affected by section [class.default.ctor]p2 of the draft C++ standard (or [class.ctor]p5 in C++11) which says:




    A defaulted default constructor for class X is defined as deleted if:

    ...

    - any non-variant non-static data member of const-qualified type (or array thereof) with no brace-or-equal-initializer does not have a user-provided default constructor,

    ...




    They possible key to fixing your issue is with the phrase with no brace-or-equal-initializer so if you provide brace-or-equal-initializer that will fix your issue e.g.:



    const int payments_per_year{12};
    const int period_length_in_months{48};


    brace-or-equal-initializer does not require braces, we can see this the grammar:



    brace-or-equal-initializer:
    = initializer-clause
    braced-init-list


    but using uniform initialization has some advantages such as making narrowing conversions ill-formed that it is worth getting used to using them.



    Both gcc and clang provide more meaningful diagnostics for this see the live godbolt session. Sometimes it can be helpful to try your code on multiple compilers, especially if you have a minimal test case like this e.g. clang says:



     warning: explicitly defaulted default constructor is implicitly deleted [-Wdefaulted-function-deleted]
    Bond() = default;
    ^
    note: default constructor of 'Bond' is implicitly deleted because field 'payments_per_year' of const-qualified type 'const int' would not be initialized
    const int payments_per_year;
    ^
    ...





    share|improve this answer



















    • 1




      It may be worth filing a bug report, the diagnostic could be more meaningful.
      – Shafik Yaghmour
      Nov 9 at 14:14






    • 1




      Some examples of [uniform initialization catching bugs that came up recently](twitter.com/shafikyaghmour/status/1058737227184844800
      – Shafik Yaghmour
      Nov 9 at 18:14






    • 2




      thank you for this detail answer.
      – Sasidiran Sangamanautram
      Nov 12 at 8:27















    up vote
    22
    down vote



    accepted










    You are being affected by section [class.default.ctor]p2 of the draft C++ standard (or [class.ctor]p5 in C++11) which says:




    A defaulted default constructor for class X is defined as deleted if:

    ...

    - any non-variant non-static data member of const-qualified type (or array thereof) with no brace-or-equal-initializer does not have a user-provided default constructor,

    ...




    They possible key to fixing your issue is with the phrase with no brace-or-equal-initializer so if you provide brace-or-equal-initializer that will fix your issue e.g.:



    const int payments_per_year{12};
    const int period_length_in_months{48};


    brace-or-equal-initializer does not require braces, we can see this the grammar:



    brace-or-equal-initializer:
    = initializer-clause
    braced-init-list


    but using uniform initialization has some advantages such as making narrowing conversions ill-formed that it is worth getting used to using them.



    Both gcc and clang provide more meaningful diagnostics for this see the live godbolt session. Sometimes it can be helpful to try your code on multiple compilers, especially if you have a minimal test case like this e.g. clang says:



     warning: explicitly defaulted default constructor is implicitly deleted [-Wdefaulted-function-deleted]
    Bond() = default;
    ^
    note: default constructor of 'Bond' is implicitly deleted because field 'payments_per_year' of const-qualified type 'const int' would not be initialized
    const int payments_per_year;
    ^
    ...





    share|improve this answer



















    • 1




      It may be worth filing a bug report, the diagnostic could be more meaningful.
      – Shafik Yaghmour
      Nov 9 at 14:14






    • 1




      Some examples of [uniform initialization catching bugs that came up recently](twitter.com/shafikyaghmour/status/1058737227184844800
      – Shafik Yaghmour
      Nov 9 at 18:14






    • 2




      thank you for this detail answer.
      – Sasidiran Sangamanautram
      Nov 12 at 8:27













    up vote
    22
    down vote



    accepted







    up vote
    22
    down vote



    accepted






    You are being affected by section [class.default.ctor]p2 of the draft C++ standard (or [class.ctor]p5 in C++11) which says:




    A defaulted default constructor for class X is defined as deleted if:

    ...

    - any non-variant non-static data member of const-qualified type (or array thereof) with no brace-or-equal-initializer does not have a user-provided default constructor,

    ...




    They possible key to fixing your issue is with the phrase with no brace-or-equal-initializer so if you provide brace-or-equal-initializer that will fix your issue e.g.:



    const int payments_per_year{12};
    const int period_length_in_months{48};


    brace-or-equal-initializer does not require braces, we can see this the grammar:



    brace-or-equal-initializer:
    = initializer-clause
    braced-init-list


    but using uniform initialization has some advantages such as making narrowing conversions ill-formed that it is worth getting used to using them.



    Both gcc and clang provide more meaningful diagnostics for this see the live godbolt session. Sometimes it can be helpful to try your code on multiple compilers, especially if you have a minimal test case like this e.g. clang says:



     warning: explicitly defaulted default constructor is implicitly deleted [-Wdefaulted-function-deleted]
    Bond() = default;
    ^
    note: default constructor of 'Bond' is implicitly deleted because field 'payments_per_year' of const-qualified type 'const int' would not be initialized
    const int payments_per_year;
    ^
    ...





    share|improve this answer














    You are being affected by section [class.default.ctor]p2 of the draft C++ standard (or [class.ctor]p5 in C++11) which says:




    A defaulted default constructor for class X is defined as deleted if:

    ...

    - any non-variant non-static data member of const-qualified type (or array thereof) with no brace-or-equal-initializer does not have a user-provided default constructor,

    ...




    They possible key to fixing your issue is with the phrase with no brace-or-equal-initializer so if you provide brace-or-equal-initializer that will fix your issue e.g.:



    const int payments_per_year{12};
    const int period_length_in_months{48};


    brace-or-equal-initializer does not require braces, we can see this the grammar:



    brace-or-equal-initializer:
    = initializer-clause
    braced-init-list


    but using uniform initialization has some advantages such as making narrowing conversions ill-formed that it is worth getting used to using them.



    Both gcc and clang provide more meaningful diagnostics for this see the live godbolt session. Sometimes it can be helpful to try your code on multiple compilers, especially if you have a minimal test case like this e.g. clang says:



     warning: explicitly defaulted default constructor is implicitly deleted [-Wdefaulted-function-deleted]
    Bond() = default;
    ^
    note: default constructor of 'Bond' is implicitly deleted because field 'payments_per_year' of const-qualified type 'const int' would not be initialized
    const int payments_per_year;
    ^
    ...






    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited Nov 12 at 8:26

























    answered Nov 9 at 14:07









    Shafik Yaghmour

    123k23309510




    123k23309510








    • 1




      It may be worth filing a bug report, the diagnostic could be more meaningful.
      – Shafik Yaghmour
      Nov 9 at 14:14






    • 1




      Some examples of [uniform initialization catching bugs that came up recently](twitter.com/shafikyaghmour/status/1058737227184844800
      – Shafik Yaghmour
      Nov 9 at 18:14






    • 2




      thank you for this detail answer.
      – Sasidiran Sangamanautram
      Nov 12 at 8:27














    • 1




      It may be worth filing a bug report, the diagnostic could be more meaningful.
      – Shafik Yaghmour
      Nov 9 at 14:14






    • 1




      Some examples of [uniform initialization catching bugs that came up recently](twitter.com/shafikyaghmour/status/1058737227184844800
      – Shafik Yaghmour
      Nov 9 at 18:14






    • 2




      thank you for this detail answer.
      – Sasidiran Sangamanautram
      Nov 12 at 8:27








    1




    1




    It may be worth filing a bug report, the diagnostic could be more meaningful.
    – Shafik Yaghmour
    Nov 9 at 14:14




    It may be worth filing a bug report, the diagnostic could be more meaningful.
    – Shafik Yaghmour
    Nov 9 at 14:14




    1




    1




    Some examples of [uniform initialization catching bugs that came up recently](twitter.com/shafikyaghmour/status/1058737227184844800
    – Shafik Yaghmour
    Nov 9 at 18:14




    Some examples of [uniform initialization catching bugs that came up recently](twitter.com/shafikyaghmour/status/1058737227184844800
    – Shafik Yaghmour
    Nov 9 at 18:14




    2




    2




    thank you for this detail answer.
    – Sasidiran Sangamanautram
    Nov 12 at 8:27




    thank you for this detail answer.
    – Sasidiran Sangamanautram
    Nov 12 at 8:27












    up vote
    49
    down vote













    The default constructor is suppressed since there are constant members that need to be explicitly initialised.



    Therefore, due to that suppression, writing Bond() = default does not reintroduce the default constructor.



    (You can see this effect by removing all the constructors in the class - you still can't instantiate a b.)



    If you drop the const from the members then all will be well; although another alternative is to supply a brace-or-equal-initializer for each const member;



    const int payments_per_year = 2;
    const int period_length_in_months = 6;


    for example.






    share|improve this answer



























      up vote
      49
      down vote













      The default constructor is suppressed since there are constant members that need to be explicitly initialised.



      Therefore, due to that suppression, writing Bond() = default does not reintroduce the default constructor.



      (You can see this effect by removing all the constructors in the class - you still can't instantiate a b.)



      If you drop the const from the members then all will be well; although another alternative is to supply a brace-or-equal-initializer for each const member;



      const int payments_per_year = 2;
      const int period_length_in_months = 6;


      for example.






      share|improve this answer

























        up vote
        49
        down vote










        up vote
        49
        down vote









        The default constructor is suppressed since there are constant members that need to be explicitly initialised.



        Therefore, due to that suppression, writing Bond() = default does not reintroduce the default constructor.



        (You can see this effect by removing all the constructors in the class - you still can't instantiate a b.)



        If you drop the const from the members then all will be well; although another alternative is to supply a brace-or-equal-initializer for each const member;



        const int payments_per_year = 2;
        const int period_length_in_months = 6;


        for example.






        share|improve this answer














        The default constructor is suppressed since there are constant members that need to be explicitly initialised.



        Therefore, due to that suppression, writing Bond() = default does not reintroduce the default constructor.



        (You can see this effect by removing all the constructors in the class - you still can't instantiate a b.)



        If you drop the const from the members then all will be well; although another alternative is to supply a brace-or-equal-initializer for each const member;



        const int payments_per_year = 2;
        const int period_length_in_months = 6;


        for example.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 15 at 8:04

























        answered Nov 9 at 11:44









        Bathsheba

        172k27244366




        172k27244366






















            up vote
            23
            down vote













            Another fix, is to specify a default value in the declaration of the constants:



            const int payments_per_year = {12};


            This can still be overridden by the valued constructor, but allows the default constructor to proceed.



            This is also a very flexible way to simplify your multiple constructor cases.






            share|improve this answer

















            • 1




              Do we need the braces?
              – Paul Sanders
              Nov 9 at 14:35






            • 2




              Equals and braces is definitely weird. Not sure what it actually means. Init from an initializer_list? Anyway: in-class member initializers are – well – initializers, and the syntax rules for initialization apply. That means either = or {}.
              – besc
              Nov 9 at 14:57






            • 6




              @PaulSanders no, you don't need braces but uniform initialization has a lot of advantages such as making narrowing conversions ill-formed that it is worth getting used to using them. See my update below.
              – Shafik Yaghmour
              Nov 9 at 17:17








            • 4




              @ShafikYaghmour: You could keep the braces and drop the equal though.
              – Matthieu M.
              Nov 9 at 20:20






            • 1




              @ShafikYaghmour: Yep, and that's part of the reason why I much prefer your answer (the other being actual standard quotes).
              – Matthieu M.
              Nov 11 at 12:02















            up vote
            23
            down vote













            Another fix, is to specify a default value in the declaration of the constants:



            const int payments_per_year = {12};


            This can still be overridden by the valued constructor, but allows the default constructor to proceed.



            This is also a very flexible way to simplify your multiple constructor cases.






            share|improve this answer

















            • 1




              Do we need the braces?
              – Paul Sanders
              Nov 9 at 14:35






            • 2




              Equals and braces is definitely weird. Not sure what it actually means. Init from an initializer_list? Anyway: in-class member initializers are – well – initializers, and the syntax rules for initialization apply. That means either = or {}.
              – besc
              Nov 9 at 14:57






            • 6




              @PaulSanders no, you don't need braces but uniform initialization has a lot of advantages such as making narrowing conversions ill-formed that it is worth getting used to using them. See my update below.
              – Shafik Yaghmour
              Nov 9 at 17:17








            • 4




              @ShafikYaghmour: You could keep the braces and drop the equal though.
              – Matthieu M.
              Nov 9 at 20:20






            • 1




              @ShafikYaghmour: Yep, and that's part of the reason why I much prefer your answer (the other being actual standard quotes).
              – Matthieu M.
              Nov 11 at 12:02













            up vote
            23
            down vote










            up vote
            23
            down vote









            Another fix, is to specify a default value in the declaration of the constants:



            const int payments_per_year = {12};


            This can still be overridden by the valued constructor, but allows the default constructor to proceed.



            This is also a very flexible way to simplify your multiple constructor cases.






            share|improve this answer












            Another fix, is to specify a default value in the declaration of the constants:



            const int payments_per_year = {12};


            This can still be overridden by the valued constructor, but allows the default constructor to proceed.



            This is also a very flexible way to simplify your multiple constructor cases.







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Nov 9 at 12:14









            Gem Taylor

            1,775216




            1,775216








            • 1




              Do we need the braces?
              – Paul Sanders
              Nov 9 at 14:35






            • 2




              Equals and braces is definitely weird. Not sure what it actually means. Init from an initializer_list? Anyway: in-class member initializers are – well – initializers, and the syntax rules for initialization apply. That means either = or {}.
              – besc
              Nov 9 at 14:57






            • 6




              @PaulSanders no, you don't need braces but uniform initialization has a lot of advantages such as making narrowing conversions ill-formed that it is worth getting used to using them. See my update below.
              – Shafik Yaghmour
              Nov 9 at 17:17








            • 4




              @ShafikYaghmour: You could keep the braces and drop the equal though.
              – Matthieu M.
              Nov 9 at 20:20






            • 1




              @ShafikYaghmour: Yep, and that's part of the reason why I much prefer your answer (the other being actual standard quotes).
              – Matthieu M.
              Nov 11 at 12:02














            • 1




              Do we need the braces?
              – Paul Sanders
              Nov 9 at 14:35






            • 2




              Equals and braces is definitely weird. Not sure what it actually means. Init from an initializer_list? Anyway: in-class member initializers are – well – initializers, and the syntax rules for initialization apply. That means either = or {}.
              – besc
              Nov 9 at 14:57






            • 6




              @PaulSanders no, you don't need braces but uniform initialization has a lot of advantages such as making narrowing conversions ill-formed that it is worth getting used to using them. See my update below.
              – Shafik Yaghmour
              Nov 9 at 17:17








            • 4




              @ShafikYaghmour: You could keep the braces and drop the equal though.
              – Matthieu M.
              Nov 9 at 20:20






            • 1




              @ShafikYaghmour: Yep, and that's part of the reason why I much prefer your answer (the other being actual standard quotes).
              – Matthieu M.
              Nov 11 at 12:02








            1




            1




            Do we need the braces?
            – Paul Sanders
            Nov 9 at 14:35




            Do we need the braces?
            – Paul Sanders
            Nov 9 at 14:35




            2




            2




            Equals and braces is definitely weird. Not sure what it actually means. Init from an initializer_list? Anyway: in-class member initializers are – well – initializers, and the syntax rules for initialization apply. That means either = or {}.
            – besc
            Nov 9 at 14:57




            Equals and braces is definitely weird. Not sure what it actually means. Init from an initializer_list? Anyway: in-class member initializers are – well – initializers, and the syntax rules for initialization apply. That means either = or {}.
            – besc
            Nov 9 at 14:57




            6




            6




            @PaulSanders no, you don't need braces but uniform initialization has a lot of advantages such as making narrowing conversions ill-formed that it is worth getting used to using them. See my update below.
            – Shafik Yaghmour
            Nov 9 at 17:17






            @PaulSanders no, you don't need braces but uniform initialization has a lot of advantages such as making narrowing conversions ill-formed that it is worth getting used to using them. See my update below.
            – Shafik Yaghmour
            Nov 9 at 17:17






            4




            4




            @ShafikYaghmour: You could keep the braces and drop the equal though.
            – Matthieu M.
            Nov 9 at 20:20




            @ShafikYaghmour: You could keep the braces and drop the equal though.
            – Matthieu M.
            Nov 9 at 20:20




            1




            1




            @ShafikYaghmour: Yep, and that's part of the reason why I much prefer your answer (the other being actual standard quotes).
            – Matthieu M.
            Nov 11 at 12:02




            @ShafikYaghmour: Yep, and that's part of the reason why I much prefer your answer (the other being actual standard quotes).
            – Matthieu M.
            Nov 11 at 12:02


















             

            draft saved


            draft discarded



















































             


            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53225106%2fwhy-doesnt-my-compiler-recognise-bond-default%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







            Popular posts from this blog

            鏡平學校

            ꓛꓣだゔៀៅຸ໢ທຮ໕໒ ,ໂ'໥໓າ໼ឨឲ៵៭ៈゎゔit''䖳𥁄卿' ☨₤₨こゎもょの;ꜹꟚꞖꞵꟅꞛေၦေɯ,ɨɡ𛃵𛁹ޝ޳ޠ޾,ޤޒޯ޾𫝒𫠁သ𛅤チョ'サノބޘދ𛁐ᶿᶇᶀᶋᶠ㨑㽹⻮ꧬ꧹؍۩وَؠ㇕㇃㇪ ㇦㇋㇋ṜẰᵡᴠ 軌ᵕ搜۳ٰޗޮ޷ސޯ𫖾𫅀ल, ꙭ꙰ꚅꙁꚊꞻꝔ꟠Ꝭㄤﺟޱސꧨꧼ꧴ꧯꧽ꧲ꧯ'⽹⽭⾁⿞⼳⽋២៩ញណើꩯꩤ꩸ꩮᶻᶺᶧᶂ𫳲𫪭𬸄𫵰𬖩𬫣𬊉ၲ𛅬㕦䬺𫝌𫝼,,𫟖𫞽ហៅ஫㆔ాఆఅꙒꚞꙍ,Ꙟ꙱エ ,ポテ,フࢰࢯ𫟠𫞶 𫝤𫟠ﺕﹱﻜﻣ𪵕𪭸𪻆𪾩𫔷ġ,ŧآꞪ꟥,ꞔꝻ♚☹⛵𛀌ꬷꭞȄƁƪƬșƦǙǗdžƝǯǧⱦⱰꓕꓢႋ神 ဴ၀க௭எ௫ឫោ ' េㇷㇴㇼ神ㇸㇲㇽㇴㇼㇻㇸ'ㇸㇿㇸㇹㇰㆣꓚꓤ₡₧ ㄨㄟ㄂ㄖㄎ໗ツڒذ₶।ऩछएोञयूटक़कयँृी,冬'𛅢𛅥ㇱㇵㇶ𥄥𦒽𠣧𠊓𧢖𥞘𩔋цѰㄠſtʯʭɿʆʗʍʩɷɛ,əʏダヵㄐㄘR{gỚṖḺờṠṫảḙḭᴮᵏᴘᵀᵷᵕᴜᴏᵾq﮲ﲿﴽﭙ軌ﰬﶚﶧ﫲Ҝжюїкӈㇴffצּ﬘﭅﬈軌'ffistfflſtffतभफɳɰʊɲʎ𛁱𛁖𛁮𛀉 𛂯𛀞నఋŀŲ 𫟲𫠖𫞺ຆຆ ໹້໕໗ๆทԊꧢꧠ꧰ꓱ⿝⼑ŎḬẃẖỐẅ ,ờỰỈỗﮊDžȩꭏꭎꬻ꭮ꬿꭖꭥꭅ㇭神 ⾈ꓵꓑ⺄㄄ㄪㄙㄅㄇstA۵䞽ॶ𫞑𫝄㇉㇇゜軌𩜛𩳠Jﻺ‚Üမ႕ႌႊၐၸဓၞၞၡ៸wyvtᶎᶪᶹစဎ꣡꣰꣢꣤ٗ؋لㇳㇾㇻㇱ㆐㆔,,㆟Ⱶヤマފ޼ޝަݿݞݠݷݐ',ݘ,ݪݙݵ𬝉𬜁𫝨𫞘くせぉて¼óû×ó£…𛅑הㄙくԗԀ5606神45,神796'𪤻𫞧ꓐ㄁ㄘɥɺꓵꓲ3''7034׉ⱦⱠˆ“𫝋ȍ,ꩲ軌꩷ꩶꩧꩫఞ۔فڱێظペサ神ナᴦᵑ47 9238їﻂ䐊䔉㠸﬎ffiﬣ,לּᴷᴦᵛᵽ,ᴨᵤ ᵸᵥᴗᵈꚏꚉꚟ⻆rtǟƴ𬎎

            Why https connections are so slow when debugging (stepping over) in Java?