Consider the following program:
#include <iostream>
void myprint(const char* fmt, ...)
{
std::cout << "1 ";
}
void myprint(const char* fmt, char *x)
{
std::cout << "2 ";
}
int main()
{
const char* s = "c";
myprint("a", s);
myprint("a", "b");
}
It produces different output:
My question is two-fold:
-
Why does a string literal bind to a non-const
char*even in the presence of-std=c++14? Isn't a string literalconstsince C++11? -
The ellipsis-overload is always ranked lowest. Why does clang select it? (one would think it doesn't allow binding to
char*but if I remove the ellipsis overload, it still does - demo)
What's going on and who is right?
Aucun commentaire:
Enregistrer un commentaire