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. General Programming
  3. C / C++ / MFC
  4. Strange error with overloaded function name

Strange error with overloaded function name

Scheduled Pinned Locked Moved C / C++ / MFC
c++jsonhelpquestion
7 Posts 4 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.
  • M Offline
    M Offline
    Mr Brainley
    wrote on last edited by
    #1

    I had this function in a class i defined :

    void AddJob(IRunnable &NewJob);

    Now there is a Windows API that is also called AddJob, but with completely different parameters and return type. The class was defined inside a static library. When i wanted to call that function in an application that linked my library :

    TestInstance.AddJob(IRunnableImplInstance);

    i got a linker error "Unresolved external". I renamed my functio now, and all works well. But i wonder why the error occured in the first place. The function had completely different parameters, return types and class context (the API is in the global namespace). I use VC++ 6. Does anyone have an explanation for that ?

    C B 2 Replies Last reply
    0
    • M Mr Brainley

      I had this function in a class i defined :

      void AddJob(IRunnable &NewJob);

      Now there is a Windows API that is also called AddJob, but with completely different parameters and return type. The class was defined inside a static library. When i wanted to call that function in an application that linked my library :

      TestInstance.AddJob(IRunnableImplInstance);

      i got a linker error "Unresolved external". I renamed my functio now, and all works well. But i wonder why the error occured in the first place. The function had completely different parameters, return types and class context (the API is in the global namespace). I use VC++ 6. Does anyone have an explanation for that ?

      C Offline
      C Offline
      Chris Meech
      wrote on last edited by
      #2

      I believe that C functions, even when compiled by a C++ compiler only differ by name and not by return type, name and parameter list for C++ member functions. Would this be the culprit?

      Chris Meech I am Canadian. [heard in a local bar] Nobody likes jerks. [espeir] Hey, I am part of a special bread, we are called smart people [Captain See Sharp] The zen of the soapbox is hard to attain...[Jörgen Sigvardsson] I wish I could remember what it was like to only have a short term memory.[David Kentley]

      M 1 Reply Last reply
      0
      • C Chris Meech

        I believe that C functions, even when compiled by a C++ compiler only differ by name and not by return type, name and parameter list for C++ member functions. Would this be the culprit?

        Chris Meech I am Canadian. [heard in a local bar] Nobody likes jerks. [espeir] Hey, I am part of a special bread, we are called smart people [Captain See Sharp] The zen of the soapbox is hard to attain...[Jörgen Sigvardsson] I wish I could remember what it was like to only have a short term memory.[David Kentley]

        M Offline
        M Offline
        Mr Brainley
        wrote on last edited by
        #3

        I don't know for shure. But i think unsell you declare a function __stdcall explicitly, it will always be translated into that long C++ symbol lingo. However, why would that result in an unresolved external linker error ? If anything it's a redefinition of a symbol, but not no definition of that symbol.

        C 1 Reply Last reply
        0
        • M Mr Brainley

          I had this function in a class i defined :

          void AddJob(IRunnable &NewJob);

          Now there is a Windows API that is also called AddJob, but with completely different parameters and return type. The class was defined inside a static library. When i wanted to call that function in an application that linked my library :

          TestInstance.AddJob(IRunnableImplInstance);

          i got a linker error "Unresolved external". I renamed my functio now, and all works well. But i wonder why the error occured in the first place. The function had completely different parameters, return types and class context (the API is in the global namespace). I use VC++ 6. Does anyone have an explanation for that ?

          B Offline
          B Offline
          Blake Miller
          wrote on last edited by
          #4

          This one is going to make you laugh :laugh: and cry :sigh: ... In the Microsoft headers, there are TWO definitions for almost every function - the ANSI version and the UNICODE version. The AddJob in the Microsoft headers is redefined as either AddJobA or AddJobW. The precompiler will see any similar text and change the name. Now, in your static library, you must NOT have included anything close to the printer header, so the AddJob stayed as 'AddJob', but in your project, when you went to use it, and maybe you directly or indirectly included the files which redefined AddJob, so it did not find AddJobA or AddJobW in your library at link time - your project's main OBJ module was looking for the wrong name. I had been tripped up by this one time a while back as well. You have to be careful naming anything requiring linkage the same as any one of the bazillion WIN32 functions out there! This would also explain why once you changed the name your 'problem' went away.

          Any sufficiently gross incompetence is nearly indistinguishable from malice.

          M R 2 Replies Last reply
          0
          • B Blake Miller

            This one is going to make you laugh :laugh: and cry :sigh: ... In the Microsoft headers, there are TWO definitions for almost every function - the ANSI version and the UNICODE version. The AddJob in the Microsoft headers is redefined as either AddJobA or AddJobW. The precompiler will see any similar text and change the name. Now, in your static library, you must NOT have included anything close to the printer header, so the AddJob stayed as 'AddJob', but in your project, when you went to use it, and maybe you directly or indirectly included the files which redefined AddJob, so it did not find AddJobA or AddJobW in your library at link time - your project's main OBJ module was looking for the wrong name. I had been tripped up by this one time a while back as well. You have to be careful naming anything requiring linkage the same as any one of the bazillion WIN32 functions out there! This would also explain why once you changed the name your 'problem' went away.

            Any sufficiently gross incompetence is nearly indistinguishable from malice.

            M Offline
            M Offline
            Mr Brainley
            wrote on last edited by
            #5

            Well, it made me laugh more than cry. I knew that most of the functions are mapped to the A and W version via macros, but i didn't make the connection. Well, you just gotta take it with humor ...

            1 Reply Last reply
            0
            • B Blake Miller

              This one is going to make you laugh :laugh: and cry :sigh: ... In the Microsoft headers, there are TWO definitions for almost every function - the ANSI version and the UNICODE version. The AddJob in the Microsoft headers is redefined as either AddJobA or AddJobW. The precompiler will see any similar text and change the name. Now, in your static library, you must NOT have included anything close to the printer header, so the AddJob stayed as 'AddJob', but in your project, when you went to use it, and maybe you directly or indirectly included the files which redefined AddJob, so it did not find AddJobA or AddJobW in your library at link time - your project's main OBJ module was looking for the wrong name. I had been tripped up by this one time a while back as well. You have to be careful naming anything requiring linkage the same as any one of the bazillion WIN32 functions out there! This would also explain why once you changed the name your 'problem' went away.

              Any sufficiently gross incompetence is nearly indistinguishable from malice.

              R Offline
              R Offline
              Rage
              wrote on last edited by
              #6

              A good candidate for the subtle bug forum...

              ~RaGE();

              I think words like 'destiny' are a way of trying to find order where none exists. - Christian Graus

              1 Reply Last reply
              0
              • M Mr Brainley

                I don't know for shure. But i think unsell you declare a function __stdcall explicitly, it will always be translated into that long C++ symbol lingo. However, why would that result in an unresolved external linker error ? If anything it's a redefinition of a symbol, but not no definition of that symbol.

                C Offline
                C Offline
                Chris Meech
                wrote on last edited by
                #7

                You're correct. I've got it backwards. My explanation would result from a redefinition error. Not what you are after. Sorry about that. :-O

                Chris Meech I am Canadian. [heard in a local bar] Nobody likes jerks. [espeir] Hey, I am part of a special bread, we are called smart people [Captain See Sharp] The zen of the soapbox is hard to attain...[Jörgen Sigvardsson] I wish I could remember what it was like to only have a short term memory.[David Kentley]

                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