C
coolpint
I am yet again confused about the process of overload resolution.
Can anyone kindly explain why the function #2 is selected over #1 when
passed 'char[15]'?
When passed 'const char[15]', the compiler complains of ambiguity as I
expected.
I was expecting to hear the same complaint when passing 'char[15]'
because I thought both required 'const qualification', but my compiler
(gcc 3.4.2) calls function #2.
So I definitely must be misunderstanding something. Please help me
understand what is going on. Thank you so much in advance!
#include <iostream>
using std::cout;
void which(const char* a, const char* b) { // #1
cout << "const char * ";
}
void which(const char (&)[15], const char (&)[15]) { // #2
cout << "const char (&)[15] ";
}
int main()
{
const char a[15] = {"Whatever"};
const char b[15] = {"Whatever"};
// which(a,b); // overload resolution failure as expected...
char c[15];
char d[15];
which(c,d); // Why does it select the "const char (&)[15]" ?
return 0;
}
Can anyone kindly explain why the function #2 is selected over #1 when
passed 'char[15]'?
When passed 'const char[15]', the compiler complains of ambiguity as I
expected.
I was expecting to hear the same complaint when passing 'char[15]'
because I thought both required 'const qualification', but my compiler
(gcc 3.4.2) calls function #2.
So I definitely must be misunderstanding something. Please help me
understand what is going on. Thank you so much in advance!
#include <iostream>
using std::cout;
void which(const char* a, const char* b) { // #1
cout << "const char * ";
}
void which(const char (&)[15], const char (&)[15]) { // #2
cout << "const char (&)[15] ";
}
int main()
{
const char a[15] = {"Whatever"};
const char b[15] = {"Whatever"};
// which(a,b); // overload resolution failure as expected...
char c[15];
char d[15];
which(c,d); // Why does it select the "const char (&)[15]" ?
return 0;
}