【发布时间】:2017-01-03 21:35:26
【问题描述】:
#include <iostream>
using namespace std;
void f(const char* arg)
{
cout << "arg is a pointer" << endl;
}
template<size_t N>
void f(const char (&arg)[N])
{
cout << "arg is an array." << endl;
}
int main()
{
f("");
}
我的编译器是 clang 3.8。
输出是:
arg 是一个指针
但是,根据cppreference.com,
无前缀字符串字面量的类型是 const char[]。
为什么重载决议的行为不符合预期?
【问题讨论】:
-
等价示例,但抽象出模板:@987654322@
-
Closely related,可能是骗子。你怎么看?
标签: c++ overloading standards string-literals