Why should default parameters be added last in C++ functions?

前端 未结 9 1626
轻奢々
轻奢々 2020-11-27 07:01

Why should default parameters be added last in C++ functions?

9条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-27 07:39

    Imagine you had a function with this prototype:

    void testFunction(bool a = false, bool b = true, bool c);
    

    Now suppose I called the function like this:

    testFunction(true, false);
    

    How is the compiler supposed to figure out which parameters I meant to supply values for?

提交回复
热议问题