Why are the next two template declarations ambiguous (so neither is more specialized than the other)? I know this question has been raised many times on Stack Overflow, but usua
The template declarations are not ambiguous; the following code compiles and runs OK:
#include
#include
using namespace std;
template
void func(char* buf, T size) {cout<<"void func(char*,T)\n";}
template
void func(char (&buf)[N], std::size_t size) {
cout<<"void func(char (&)[],size_t)\n";}
int main() {
char buf[3];
func(buf, 2);
func<3>(buf, 2);
func(reinterpret_cast(buf), 2);
//next is ambiguous
//func(reinterpret_cast(buf), size_t(2));
func<3>(reinterpret_cast(buf), size_t(2));
return 0;
}
However, the commented-out call is ambiguous. To disambiguate it use:
func<3>(reinterpret_cast(buf), size_t(2));
This works OK and calls the correct function.