function overload problem:(char) and (char*)
-
Did you try calling fun(0*)? It's obvious that you're passing a single char (the zero) to the function, so the compiler will call the fun(char) overload. Just put an asterisk and everything should work. Ok, I reckon, this is horrible, but it's not worse than "the compiler is having fun()" I see dead pixels Yes, even I am blogging now!
what about fun(*0). This will lead to the first address in memory and then will have some fun with it :) "Aerodynamically, the bumble bee shouldn't be able to fly, but the bumble bee doesn't know it so it goes on flying anyway." - Mary Kay Ash My Articles
-
It was a joke, programming questions are to be posted in the programming fora. This is the lounge, people asking programming questions in the lounge will be put in the comfy chair. I will probably regret this, but here is the real answer: When you pass the literal 0 to your function, the compiler will have no way of knowing if it is (char) 0 or (char *) 0. You will have to explicitly type cast it. In the Visual C++ forum you would have had the opportunity to get a better answer from eg. Christian Graus involving standard C++ type casts, I can only offer C style casts :-) : fun((char *) 0) or fun((char) 0). "After all it's just text at the end of the day. - Colin Davies "For example, when a VB programmer comes to my house, they may say 'does your pool need cleaning, sir ?' " - Christian Graus
-
I call fun(0),the compiler display message "ambiguous call...",when I call fun(1)(passing a value which is not zero),the compiler call fun(char),why?? your friend:bobi
on top of this page on the right you see "Message Boards", if you click on that you will get: OR a dropdown menu OR it's a link If you get the dropdownmenu click on the Visual C++ and you will be taken to the C++ forum, else you will get a bunch of links including Visual C++, which will also take you to the C++ forum. When you get there (the Visual C++ forum) kindly ask your question again and it will probably be answered without jokes. good luck. No hurries, no worries.
-
I call fun(0),the compiler display message "ambiguous call...",when I call fun(1)(passing a value which is not zero),the compiler call fun(char),why?? your friend:bobi
Because 0 is a valid pointer constant in C++, 1 isn't. Since 1 isn't a valid pointer constant, the compiler will ignore any
fun
s with taking pointers as argument. Anyway,NO PROGRAMMING QUESTIONS IN THE LOUNGE!
Next time, we'll demand your first born. -- My name in Katakana is ヨルゲン. My name in German is Jörgen. My name in Mandarin/Kanji is 乔尔根 西格瓦德森. My name in Korean is 요르겐. I blog too now[^] -
Because 0 is a valid pointer constant in C++, 1 isn't. Since 1 isn't a valid pointer constant, the compiler will ignore any
fun
s with taking pointers as argument. Anyway,NO PROGRAMMING QUESTIONS IN THE LOUNGE!
Next time, we'll demand your first born. -- My name in Katakana is ヨルゲン. My name in German is Jörgen. My name in Mandarin/Kanji is 乔尔根 西格瓦德森. My name in Korean is 요르겐. I blog too now[^]Jörgen Sigvardsson wrote: Next time, we'll demand your first born. Your really want that? :p xacc-ide 0.0.15 now with C#, MSIL, C, XML, ASP.NET, Nemerle, MyXaml and HLSL coloring - Screenshots
-
It was a joke, programming questions are to be posted in the programming fora. This is the lounge, people asking programming questions in the lounge will be put in the comfy chair. I will probably regret this, but here is the real answer: When you pass the literal 0 to your function, the compiler will have no way of knowing if it is (char) 0 or (char *) 0. You will have to explicitly type cast it. In the Visual C++ forum you would have had the opportunity to get a better answer from eg. Christian Graus involving standard C++ type casts, I can only offer C style casts :-) : fun((char *) 0) or fun((char) 0). "After all it's just text at the end of the day. - Colin Davies "For example, when a VB programmer comes to my house, they may say 'does your pool need cleaning, sir ?' " - Christian Graus
jan larsen wrote: I will probably regret this, but here is the real answer: Shame on you! You can't stop yourself to help people, can you, you bloody socialist evildoer :-D
Fold With Us! Sie wollen mein Herz am rechten Fleck, doch Seh' ich dann nach unten weg Da schlägt es links!
-
Jörgen Sigvardsson wrote: Next time, we'll demand your first born. Your really want that? :p xacc-ide 0.0.15 now with C#, MSIL, C, XML, ASP.NET, Nemerle, MyXaml and HLSL coloring - Screenshots
No, but he will probably want his first born more than I do. That's sort of the point. ;P -- My name in Katakana is ヨルゲン. My name in German is Jörgen. My name in Mandarin/Kanji is 乔尔根 西格瓦德森. My name in Korean is 요르겐. I blog too now[^]
-
Jörgen Sigvardsson wrote: Next time, we'll demand your first born. Your really want that? :p xacc-ide 0.0.15 now with C#, MSIL, C, XML, ASP.NET, Nemerle, MyXaml and HLSL coloring - Screenshots
Please don't ask![^] :-D
Fold With Us! Sie wollen mein Herz am rechten Fleck, doch Seh' ich dann nach unten weg Da schlägt es links!
-
It was a joke, programming questions are to be posted in the programming fora. This is the lounge, people asking programming questions in the lounge will be put in the comfy chair. I will probably regret this, but here is the real answer: When you pass the literal 0 to your function, the compiler will have no way of knowing if it is (char) 0 or (char *) 0. You will have to explicitly type cast it. In the Visual C++ forum you would have had the opportunity to get a better answer from eg. Christian Graus involving standard C++ type casts, I can only offer C style casts :-) : fun((char *) 0) or fun((char) 0). "After all it's just text at the end of the day. - Colin Davies "For example, when a VB programmer comes to my house, they may say 'does your pool need cleaning, sir ?' " - Christian Graus
sorry, nothing personal. :rolleyes:
Pandoras Gift #44: Hope. The one that keeps you on suffering.
aber.. "Wie gesagt, der Scheiss is' Therapie"
boost your code || Fold With Us! || sighist | doxygen -
It was a joke, programming questions are to be posted in the programming fora. This is the lounge, people asking programming questions in the lounge will be put in the comfy chair. I will probably regret this, but here is the real answer: When you pass the literal 0 to your function, the compiler will have no way of knowing if it is (char) 0 or (char *) 0. You will have to explicitly type cast it. In the Visual C++ forum you would have had the opportunity to get a better answer from eg. Christian Graus involving standard C++ type casts, I can only offer C style casts :-) : fun((char *) 0) or fun((char) 0). "After all it's just text at the end of the day. - Colin Davies "For example, when a VB programmer comes to my house, they may say 'does your pool need cleaning, sir ?' " - Christian Graus
I can understand.but I define another two:fun(int) and fun(int*),then I call fun(0),the compiler will compile successfully, and fun(0) will select fun(int) instead of fun(int*).why? thank your suggestion,I will go to the visual C++ forum. your friend:bobi