I can't find out why calls of f are ambigiuous :/ I know that the three declarations are ok but in this case this isn't working..
#include <iostream>
using namespace std;
void f(int);
void f(int &);
void f(const int &);
void f(int a);
void f(int &a);
void f(const int &a);
int main()
{
int i=1;
const int ic=2;
int &ri=i;
const int & rc=ic;
f(i);
f(ic);
f(ri);
f(rc);
return 0;
}
I know that the three declarations are ok
How? All arguments are convertible to int
. The ambiguity is clear.
Do you think int x = rc;
won't compile?
I think your confusion stems from void f(int);
. Since the parameter is passed by value , anything that can be copied in a new int
matches this overload.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.