Hi bonczz,
First, please read
http://cfaj.freeshell.org/google/ to see how you
should quote context in your replies.
Going back to the original code:
bonczz@gmail.com <bonczz@gmail.com> wrote:[color=blue]
> #include <iostream>
> using std::cout;
>
> void which(const char* a, const char* b) { // #1
> cout << "const char * ";
> }
>
> void which(const char (&array)[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;
> }[/color]
Using Visual Studio .NET 2003, which is also known as
Visual C++ .NET 7.1, I get the following compiler error:
test.cpp
test.cpp(20) : error C2668: 'which' : ambiguous call to overloaded function
test.cpp(8): could be 'void which(const char (&)[15],const char (&)[15]) '
test.cpp(4): or 'void which(const char *,const char *)'
while trying to match the argument list '(char [15], char [15])'
However, Comeau online compiles it. Someone who has better knowledge of
the function overload resolution rules will have to elaborate.
bonczz@gmail.com <bonczz@gmail.com> wrote:[color=blue]
> (0) Then how can I give it a name? because "const char (&)[15] array"
> does not work
> and I need a name, for example I want to ask what is its 4th element (
> array[3] )[/color]
You can say:
const char (&array)[15]
[color=blue]
> (1) And why I need the semicolons (I need because it does not compile
> without them)?[/color]
I'm not sure which semicolons you are talking about. C++ needs a lot of
semicolons :)
--
Marcus Kwok