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. VC++ Linking error to do with += Operator

VC++ Linking error to do with += Operator

Scheduled Pinned Locked Moved C / C++ / MFC
helpc++question
5 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.
  • A Offline
    A Offline
    ajisthekingofpop
    wrote on last edited by
    #1

    I have created a class with the following defined: friend CStrTemp& operator += ( CStrTemp& i, const CStrTemp& s ); and then: template CStrTemp& operator += ( CStrTemp& i, const CStrTemp& s ) { ///code and return } Everything compiled but when it tries to create the executable it throws up the followinf error: CString.obj : error LNK2019: unresolved external symbol "class CStrTemp & __cdecl operator+=(class CStrTemp &,class CStrTemp const &)" (??Y@YAAAV?$CStrTemp@D@@AAV0@ABV0@@Z) referenced in function "class CString __cdecl operator+(char,class CString const &)" (??H@YA?AVCString@@DABV0@@Z) Any help would be appreciated as I just cannot understand why it is not working.

    R D Z 3 Replies Last reply
    0
    • A ajisthekingofpop

      I have created a class with the following defined: friend CStrTemp& operator += ( CStrTemp& i, const CStrTemp& s ); and then: template CStrTemp& operator += ( CStrTemp& i, const CStrTemp& s ) { ///code and return } Everything compiled but when it tries to create the executable it throws up the followinf error: CString.obj : error LNK2019: unresolved external symbol "class CStrTemp & __cdecl operator+=(class CStrTemp &,class CStrTemp const &)" (??Y@YAAAV?$CStrTemp@D@@AAV0@ABV0@@Z) referenced in function "class CString __cdecl operator+(char,class CString const &)" (??H@YA?AVCString@@DABV0@@Z) Any help would be appreciated as I just cannot understand why it is not working.

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

      What is CStrTemp ? Is it derived from something ?

      ~RaGE();

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

      1 Reply Last reply
      0
      • A ajisthekingofpop

        I have created a class with the following defined: friend CStrTemp& operator += ( CStrTemp& i, const CStrTemp& s ); and then: template CStrTemp& operator += ( CStrTemp& i, const CStrTemp& s ) { ///code and return } Everything compiled but when it tries to create the executable it throws up the followinf error: CString.obj : error LNK2019: unresolved external symbol "class CStrTemp & __cdecl operator+=(class CStrTemp &,class CStrTemp const &)" (??Y@YAAAV?$CStrTemp@D@@AAV0@ABV0@@Z) referenced in function "class CString __cdecl operator+(char,class CString const &)" (??H@YA?AVCString@@DABV0@@Z) Any help would be appreciated as I just cannot understand why it is not working.

        D Offline
        D Offline
        David Crow
        wrote on last edited by
        #3

        ajisthekingofpop wrote:

        unresolved external symbol...referenced in function "class CString __cdecl operator+(

        What does the operator+ method look like?


        "Money talks. When my money starts to talk, I get a bill to shut it up." - Frank

        "Judge not by the eye but by the heart." - Native American Proverb

        1 Reply Last reply
        0
        • A ajisthekingofpop

          I have created a class with the following defined: friend CStrTemp& operator += ( CStrTemp& i, const CStrTemp& s ); and then: template CStrTemp& operator += ( CStrTemp& i, const CStrTemp& s ) { ///code and return } Everything compiled but when it tries to create the executable it throws up the followinf error: CString.obj : error LNK2019: unresolved external symbol "class CStrTemp & __cdecl operator+=(class CStrTemp &,class CStrTemp const &)" (??Y@YAAAV?$CStrTemp@D@@AAV0@ABV0@@Z) referenced in function "class CString __cdecl operator+(char,class CString const &)" (??H@YA?AVCString@@DABV0@@Z) Any help would be appreciated as I just cannot understand why it is not working.

          Z Offline
          Z Offline
          Zac Howland
          wrote on last edited by
          #4

          There are a few problems here. First, depending on your compiler, some versions of MFC's CString have a hidden class called CStrTemp. Thus, defining your own class with the same name can cause problems (one of the reasons MFC should have put its stuff in a namespace, and the reason you should do the same). Second, you defined the function as: friend CStrTemp& operator += ( CStrTemp& i, const CStrTemp& s );, but implemented it as template CStrTemp& operator += ( CStrTemp& i, const CStrTemp& s ) (I'm assuming you just mistyped the <> signs and that the template declaration should actually read template<class T>). If you defined the class as a template, that will work, but you will need to declare it similar to the following: friend CStrTemp<T> operator+=(CStrTemp<T>& i, const CStrTemp<T>& s) and implement it as template<class T> CStrTemp<T>& operator+=(CStrTemp<T>& i, const CStrTemp<T>& s) {...} Put your code in a namespace and fix your template declarations and this should clear some things up.

          If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week Zac

          R 1 Reply Last reply
          0
          • Z Zac Howland

            There are a few problems here. First, depending on your compiler, some versions of MFC's CString have a hidden class called CStrTemp. Thus, defining your own class with the same name can cause problems (one of the reasons MFC should have put its stuff in a namespace, and the reason you should do the same). Second, you defined the function as: friend CStrTemp& operator += ( CStrTemp& i, const CStrTemp& s );, but implemented it as template CStrTemp& operator += ( CStrTemp& i, const CStrTemp& s ) (I'm assuming you just mistyped the <> signs and that the template declaration should actually read template<class T>). If you defined the class as a template, that will work, but you will need to declare it similar to the following: friend CStrTemp<T> operator+=(CStrTemp<T>& i, const CStrTemp<T>& s) and implement it as template<class T> CStrTemp<T>& operator+=(CStrTemp<T>& i, const CStrTemp<T>& s) {...} Put your code in a namespace and fix your template declarations and this should clear some things up.

            If you decide to become a software engineer, you are signing up to have a 1/2" piece of silicon tell you exactly how stupid you really are for 8 hours a day, 5 days a week Zac

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

            Zac Howland wrote:

            some versions of MFC's CString have a hidden class called CStrTemp

            Now this is interesting. Thanks for sharing it. :cool:

            ~RaGE();

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

            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