consider following code:
#include <iostream> void foo(int m); void foo(int &k); int main() { foo(5); // ok, because there no ambiguity int m = 5; //foo(m); // compile-time error, because of ambiguity foo(m + 0); // ok, because it's expression of type int , not object's lvalue } void foo(int m) { std::cout << "by value\n"; } void foo(int &k) { std::cout << "by reference\n"; } i understand introduces ambiguity foo(m), allowed, when expression of type int (or can converted int)?
i have tried find standard reference on this, yet no luck.
disclaimer: note it's not duplicate of function overloading based on value vs. const reference. const references different can assigned rvalues, opposite "ordinary", non-const references.
yes, allowed.
there no rule prevent overload.
[c++14: 13.1/1]:not function declarations can overloaded. cannot overloaded specified here. [..]
[c++14: 13.1/2]:(blah blah lots of exceptions not including case)
it extremely limiting language prohibit function overloads may ambiguous in scenarios calls, , no reason might add!
Comments
Post a Comment