
www.Usenet.com
| <-- __Chronological__ --> | <-- __Thread__ --> |
"Kuznetsov Dmitriy" <[EMAIL PROTECTED]> skrev i en meddelelse
news:[EMAIL PROTECTED]
> Hi all, can anybody explain to me why compiler choose 'void take_str
(char*
> str)' to call
> in next program.
>
> #include <iostream>
>
> void take_str (char* str)
> {
> std::cout << "char*" << std::endl;
> }
>
> void take_str (const char* str)
> {
> std::cout << "const char*" << std::endl;
> }
>
> int main(int argc, char* argv[])
> {
> take_str ("const char*");
> return 0;
> }
Hi Kuznetsov
This is because "const char*" (your string) is a char* and not as char
const*. This is nonintuitive of course, but C had it that way and it has
been preserved for compatibility.
Kind regards
Peter
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
| <-- __Chronological__ --> | <-- __Thread__ --> |