【发布时间】:2016-10-21 15:44:55
【问题描述】:
- 为什么以下示例代码不会产生歧义
- 有没有办法调用第二个版本? (如果这不是错误)
#include <iostream>
using namespace std;
void foo(const int*){cout << "no ref";}
void foo(const int*&){cout << "on ref";}
int main()
{
int* i=nullptr;
foo(i);
}
编辑:
这个
#include <iostream>
using namespace std;
void foo(const int){cout << "no ref";}
void foo(const int&){cout << "on ref";}
int main()
{
int i=0;
foo(i);
}
确实会产生歧义。
顺便去掉const产生的歧义。
编译器:g++5.3.0 带有标志 --std=c++14
【问题讨论】:
标签: c++ pointers reference overloading overload-resolution