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. C / C++ / MFC
  3. CList/CArray duplicate link problem

CList/CArray duplicate link problem

Scheduled Pinned Locked Moved C / C++ / MFC
4 Posts 2 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.
  • W Offline
    W Offline
    Wayne Janaway
    wrote on last edited by
    #1

    I have a CList of ptrs (ptrList) to CItems in a supporting class (CGroup) of my program, with an override of SerializeElements. This works fine until I add a second CArray or CList of the same type of ptr as a member of CMainframe. Then I get a linker error: Group.obj : error LNK2005: "void __stdcall SerializeElements(class CArchive &,class CItem * *,int)" (?SerializeElements@@YGXAAVCArchive@@PAPAVCItem@@H@Z) already defined in MainFrm.obj I gather that the linker is unable to deal with an alternate version of the SerializeElements function, but how do I get around this while keeping the SerializeElements override in the CGroup.cpp file? Any help is appreciated. Thanks WJ

    T 1 Reply Last reply
    0
    • W Wayne Janaway

      I have a CList of ptrs (ptrList) to CItems in a supporting class (CGroup) of my program, with an override of SerializeElements. This works fine until I add a second CArray or CList of the same type of ptr as a member of CMainframe. Then I get a linker error: Group.obj : error LNK2005: "void __stdcall SerializeElements(class CArchive &,class CItem * *,int)" (?SerializeElements@@YGXAAVCArchive@@PAPAVCItem@@H@Z) already defined in MainFrm.obj I gather that the linker is unable to deal with an alternate version of the SerializeElements function, but how do I get around this while keeping the SerializeElements override in the CGroup.cpp file? Any help is appreciated. Thanks WJ

      T Offline
      T Offline
      Tomasz Sowinski
      wrote on last edited by
      #2

      So you have two definitions of SerializeElements(CArchive&, CItem **, int)? Do they differ? Tomasz Sowinski -- http://www.shooltz.com

      W 1 Reply Last reply
      0
      • T Tomasz Sowinski

        So you have two definitions of SerializeElements(CArchive&, CItem **, int)? Do they differ? Tomasz Sowinski -- http://www.shooltz.com

        W Offline
        W Offline
        Wayne Janaway
        wrote on last edited by
        #3

        I have only created one definition of SerializeElements, the one in class CGroup. This was needed to serialize the items pointed to rather than the ptrs in the list. I'm guessing that the linker is somehow first linking the default version when it encounters it in CMainFrame, then is unable to resolve what it percieves as an alternate version ( which does differ in function ) in CGroup. Actually, the SerializeElements method will never be used in the MainFrame Array, but the linker doesn't know that. --WJ

        T 1 Reply Last reply
        0
        • W Wayne Janaway

          I have only created one definition of SerializeElements, the one in class CGroup. This was needed to serialize the items pointed to rather than the ptrs in the list. I'm guessing that the linker is somehow first linking the default version when it encounters it in CMainFrame, then is unable to resolve what it percieves as an alternate version ( which does differ in function ) in CGroup. Actually, the SerializeElements method will never be used in the MainFrame Array, but the linker doesn't know that. --WJ

          T Offline
          T Offline
          Tomasz Sowinski
          wrote on last edited by
          #4

          You should make one or both SerializeElements static. 'Static' function is visible only within the containing .cpp or .c file. The other solution would be putting these functions in unnamed namespace. Tomasz Sowinski -- http://www.shooltz.com

          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