Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. The Lounge
  3. function overload problem:(char) and (char*)

function overload problem:(char) and (char*)

Scheduled Pinned Locked Moved The Lounge
helptutorialquestion
21 Posts 10 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    bobi_zcl
    wrote on last edited by
    #1

    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

    J A D 4 Replies Last reply
    0
    • B bobi_zcl

      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

      J Offline
      J Offline
      jan larsen
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      • B bobi_zcl

        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

        A Offline
        A Offline
        Aamir Butt
        wrote on last edited by
        #3

        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

        J 1 Reply Last reply
        0
        • B bobi_zcl

          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

          J Offline
          J Offline
          jan larsen
          wrote on last edited by
          #4

          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

          C B 2 Replies Last reply
          0
          • A Aamir Butt

            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

            J Offline
            J Offline
            jan larsen
            wrote on last edited by
            #5

            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

            1 Reply Last reply
            0
            • J jan larsen

              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

              C Offline
              C Offline
              CP Visitor
              wrote on last edited by
              #6

              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?

              J 1 Reply Last reply
              0
              • B bobi_zcl

                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

                D Offline
                D Offline
                Daniel Turini
                wrote on last edited by
                #7

                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!

                J B A 3 Replies Last reply
                0
                • J jan larsen

                  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

                  B Offline
                  B Offline
                  bobi_zcl
                  wrote on last edited by
                  #8

                  I still havn't understand what you said,Can you explain? your friend:bobi

                  J 1 Reply Last reply
                  0
                  • C CP Visitor

                    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?

                    J Offline
                    J Offline
                    jan larsen
                    wrote on last edited by
                    #9

                    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

                    1 Reply Last reply
                    0
                    • D Daniel Turini

                      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!

                      J Offline
                      J Offline
                      jan larsen
                      wrote on last edited by
                      #10

                      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

                      1 Reply Last reply
                      0
                      • D Daniel Turini

                        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!

                        B Offline
                        B Offline
                        bobi_zcl
                        wrote on last edited by
                        #11

                        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

                        V J 2 Replies Last reply
                        0
                        • D Daniel Turini

                          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!

                          A Offline
                          A Offline
                          Aamir Butt
                          wrote on last edited by
                          #12

                          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

                          1 Reply Last reply
                          0
                          • B bobi_zcl

                            I still havn't understand what you said,Can you explain? your friend:bobi

                            J Offline
                            J Offline
                            jan larsen
                            wrote on last edited by
                            #13

                            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

                            K P B 3 Replies Last reply
                            0
                            • B bobi_zcl

                              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

                              V Offline
                              V Offline
                              V 0
                              wrote on last edited by
                              #14

                              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.

                              1 Reply Last reply
                              0
                              • B bobi_zcl

                                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

                                J Offline
                                J Offline
                                Jorgen Sigvardsson
                                wrote on last edited by
                                #15

                                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 funs 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[^]

                                L 1 Reply Last reply
                                0
                                • J Jorgen Sigvardsson

                                  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 funs 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[^]

                                  L Offline
                                  L Offline
                                  leppie
                                  wrote on last edited by
                                  #16

                                  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

                                  J K 2 Replies Last reply
                                  0
                                  • J jan larsen

                                    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

                                    K Offline
                                    K Offline
                                    KaRl
                                    wrote on last edited by
                                    #17

                                    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!

                                    1 Reply Last reply
                                    0
                                    • L leppie

                                      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

                                      J Offline
                                      J Offline
                                      Jorgen Sigvardsson
                                      wrote on last edited by
                                      #18

                                      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[^]

                                      1 Reply Last reply
                                      0
                                      • L leppie

                                        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

                                        K Offline
                                        K Offline
                                        KaRl
                                        wrote on last edited by
                                        #19

                                        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!

                                        1 Reply Last reply
                                        0
                                        • J jan larsen

                                          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

                                          P Offline
                                          P Offline
                                          peterchen
                                          wrote on last edited by
                                          #20

                                          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

                                          1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • World
                                          • Users
                                          • Groups