CList/CArray duplicate link problem
-
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
-
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
So you have two definitions of SerializeElements(CArchive&, CItem **, int)? Do they differ? Tomasz Sowinski -- http://www.shooltz.com
-
So you have two definitions of SerializeElements(CArchive&, CItem **, int)? Do they differ? Tomasz Sowinski -- http://www.shooltz.com
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
-
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
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