4

foo(const char *) is chosen over template version for "hello". How to make the compiler choose template version instead?

#include <iostream>

template <size_t N>
void foo(const char (&)[N])
{
    std::cout << N << std::endl;
}

void foo(const char *)
{
    std::cout << "char*" << std::endl;
}

int main()
{
    foo("hello");
    char a[] = "world";
    foo(a);
}
Derek
  • 557
  • 1
  • 4
  • 16

0 Answers0