function overload problem:(char) and (char*)
-
Hi,everyone: I write two function: void fun(char) and void fun(char*).when I call fun(0),the compiler display message"ambiguous call to overloaded function";but,I call fun(1),the compiler call fun(char). Anyone can tell me how to explain it? your friend:bobi
-
Hi,everyone: I write two function: void fun(char) and void fun(char*).when I call fun(0),the compiler display message"ambiguous call to overloaded function";but,I call fun(1),the compiler call fun(char). Anyone can tell me how to explain it? your friend:bobi
Don't bother, it's just the compiler having
fun()
"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 -
Hi,everyone: I write two function: void fun(char) and void fun(char*).when I call fun(0),the compiler display message"ambiguous call to overloaded function";but,I call fun(1),the compiler call fun(char). Anyone can tell me how to explain it? your friend:bobi
Come on guys. We have got a programming question in the LOUNGE. Hoping to see some of the best from you people :) "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
-
Hi,everyone: I write two function: void fun(char) and void fun(char*).when I call fun(0),the compiler display message"ambiguous call to overloaded function";but,I call fun(1),the compiler call fun(char). Anyone can tell me how to explain it? your friend:bobi
By the way, the answer is pretty simple, ask in the right forum, Visual C++, and you will get it :-) "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
-
Come on guys. We have got a programming question in the LOUNGE. Hoping to see some of the best from you people :) "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
Aw, it WAS my best... :rolleyes: "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
-
By the way, the answer is pretty simple, ask in the right forum, Visual C++, and you will get it :-) "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: For example, when a VB programmer comes to my house, they may say 'does your pool need cleaning, sir ?' " This not correct English, no?
-
Hi,everyone: I write two function: void fun(char) and void fun(char*).when I call fun(0),the compiler display message"ambiguous call to overloaded function";but,I call fun(1),the compiler call fun(char). Anyone can tell me how to explain it? your friend:bobi
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!
-
By the way, the answer is pretty simple, ask in the right forum, Visual C++, and you will get it :-) "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: For example, when a VB programmer comes to my house, they may say 'does your pool need cleaning, sir ?' " This not correct English, no?
What did you expect from VB programmers :-) "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
-
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!
Daniel Turini wrote: Did you try calling fun(0*)? Oh that one's obvious, as long as he remember to add the compiler hint at the end of the code like this:
int main()
{
fun(0*);
}
*: It's (char) 0, not (void *) 0, now go on..."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
-
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!
-
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