Function overloading — two functions only differ by a default parameter

前端 未结 7 2110
有刺的猬
有刺的猬 2020-12-06 07:21
class A{
    public:
        void foo(int x)
        {
            cout << \"foo with one\\n\";
        }

        void foo(int x, int y=10)
        {
                 


        
7条回答
  •  无人及你
    2020-12-06 08:08

    I think you can't. Because function/operator overloading is resolved by compiler at compile time. So overloading a function just by providing a default argument will cause ambiguity and compiler error.

提交回复
热议问题