Function Overloading Based on Value vs. Const Reference

前端 未结 6 853
借酒劲吻你
借酒劲吻你 2020-11-27 06:21

Does declaring something like the following

void foo(int x)        { std::cout << \"foo(int)\"         << std::endl; }
void foo(const int &x)         


        
6条回答
  •  一整个雨季
    2020-11-27 07:05

    How would the caller be able to differentiate between them?

    It cannot be differentiated in this case. Both the overloaded functions have the same type of primitive data type as the argument. And taking by reference doesn't count for a different type.

提交回复
热议问题