Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9125051
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T06:42:41+00:00 2026-06-17T06:42:41+00:00

I am using boost serialization to save and load data. My goal is to

  • 0

I am using boost serialization to save and load data. My goal is to store a vector containing objects. Their type is a derived class.

The linker tells me that there is some stuff that is already defined in the obj-file of another class (which has nothing to do with my serialization).

Can someone tell me what is wrong with my code? Am I missing something?
Is my code for serializing derived classes correct?


This is the output:

Error 1 error LNK2005: "public: static struct boost::archive::detail::extra_detail::guid_initializer const & const boost::archive::detail::extra_detail::init_guid::g" (?g@?$init_guid@VCYesNoElement@@@extra_detail@detail@archive@boost@@2ABU?$guid_initializer@VCYesNoElement@@@2345@B) already defined in ElementFactory.obj

Error 2 error LNK2005: "public: static struct boost::archive::detail::extra_detail::guid_initializer const & const boost::archive::detail::extra_detail::init_guid::g" (?g@?$init_guid@VCYesNoElement@@@extra_detail@detail@archive@boost@@2ABU?$guid_initializer@VCYesNoElement@@@2345@B) already defined in ElementFactory.obj

Error 3 error LNK2005: "public: static struct boost::archive::detail::extra_detail::guid_initializer const & const boost::archive::detail::extra_detail::init_guid::g" (?g@?$init_guid@VCYesNoElement@@@extra_detail@detail@archive@boost@@2ABU?$guid_initializer@VCYesNoElement@@@2345@B) already defined in ElementFactory.obj

Error 4 error LNK2005: "public: static struct boost::archive::detail::extra_detail::guid_initializer const & const boost::archive::detail::extra_detail::init_guid::g" (?g@?$init_guid@VCYesNoElement@@@extra_detail@detail@archive@boost@@2ABU?$guid_initializer@VCYesNoElement@@@2345@B) already defined in ElementFactory.obj

Error 5 error LNK2005: "public: static struct boost::archive::detail::extra_detail::guid_initializer const & const boost::archive::detail::extra_detail::init_guid::g" (?g@?$init_guid@VCYesNoElement@@@extra_detail@detail@archive@boost@@2ABU?$guid_initializer@VCYesNoElement@@@2345@B) already defined in ElementFactory.obj


This is the base class (IElement):

#ifndef __ELEMENT_H__
#define __ELEMENT_H__

#include <string>
#include <vector>
#include <cassert>

#include <boost\serialization\base_object.hpp>
#include <boost\serialization\export.hpp>
#include <boost\archive\binary_iarchive.hpp>
#include <boost\archive\binary_oarchive.hpp>

typedef enum eElementType
{
    eMultipleChoice,
    eYesNo,
    eKeyword,
    eText,
    eCloze
} eType;

class IElement
{

public:
    virtual ~IElement();

    void SetFrontText( const std::string& question );
    std::string GetFrontText();
    virtual eType GetType() = 0;

    int GetStatus();
    void StatusUp();
    void StatusDown();
    void Reset();

    template<class Archive>
    void serialize(Archive & ar, const unsigned int version)
    {
        ar & boost::serialization::make_nvp( "Status", m_status );
        ar & boost::serialization::make_nvp( "FrontText", m_frontText );
    }

protected:
    bool VectorContainsString( std::vector<std::string>* _vec, const std::string& _str );
    bool RemoveStringFromVector( std::vector<std::string>* _vec, const std::string& _str );

    std::string m_frontText;

    int m_status;
};
BOOST_SERIALIZATION_ASSUME_ABSTRACT( IElement )

#endif // __ELEMENT_H__

This is the derived class (CYesNoElement):

#ifndef __YES_NO_ELEMENT_H__
#define __YES_NO_ELEMENT_H__

#include "Element.h"

class CYesNoElement : public IElement
{
public:
    CYesNoElement();
    virtual ~CYesNoElement();

    bool GetSolution();
    void SetSolution( bool solution );

    bool check( bool given_answer );

    // IElement
    virtual eType GetType();

    template<class Archive>
    void serialize(Archive & ar, unsigned int file_version)
    {
        BOOST_SERIALIZATION_BASE_OBJECT_NVP( IElement );
        ar & boost::serialization::make_nvp( "Solution", m_solution );
    }

private:
    bool m_solution;
};
BOOST_CLASS_EXPORT(CYesNoElement)

#endif // __YES_NO_ELEMENT_H__

This is the class CElementFactory where the linker errors are hinting at:

#ifndef __ELEMENTFACTORY_H__
#define __ELEMENTFACTORY_H__

#include "ClozeElement.h"
#include "KeywordElement.h"
#include "MultipleChoiceElement.h"
#include "TextElement.h"
#include "YesNoElement.h"

class CElementFactory
{
public:
    CElementFactory(void);
    virtual ~CElementFactory(void);

    IElement* CreateElement( eType type );

private:
    CClozeElement* CreateClozeElement();
    CKeywordElement* CreateKeywordElement();
    CMultipleChoiceElement* CreateMultipleChoiceElement();
    CTextElement* CreateTextElement();
    CYesNoElement* CreateYesNoElement();
};

#endif // __ELEMENTFACTORY_H__
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T06:42:42+00:00Added an answer on June 17, 2026 at 6:42 am

    Put BOOST_CLASS_EXPORT(CYesNoElement) in the .cpp.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was able to save my data onto disk using boost serialization. However, I
How would you serialize/deserialize this class using boost::serialization? #include <vector> struct Foo { struct
When trying to save the database using boost serialization, I encounter the segfault that
I am trying to serialize a class to a string using the boost serialization
I am using the boost example code to store a vector of pointers of
Is it possible to serialize data structures (using boost::serialization) into string variable or buffer
so I'm using the boost::serialization library, and I'm trying to overide how a class
I am using boost.serialization. some sample code use BOOST_SERIALIZATION_NVP in serialize method: template<class Archive>
I am not using boost libraries. How can i do this using STL? class
I am using boost::any to store pointers and was wondering if there was a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.