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 3798074
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T13:30:45+00:00 2026-05-19T13:30:45+00:00

I’m trying to use boost::serialization to replace one part of an existing project that

  • 0

I’m trying to use boost::serialization to replace one part of an existing project that implements its own methods for serialization but are not that good.
However, I’m facing some problems because the application uses MFC. I tried to serialize the CString as follows

template<class Archive>
void save(Archive & ar, CString & s, const unsigned int version) {  
  using boost::serialization::make_nvp;
  const std::basic_string<TCHAR> ss((LPCTSTR)s);
  ar & make_nvp("String", ss);
}
template<class Archive>
void load(Archive & ar, CString & s, const unsigned int version) {  
  using boost::serialization::make_nvp;
  std::string ss;
  ar & make_nvp("String",ss);
  s = ss.c_str;
}

But I’m getting some errors

boost_1_45_0\boost\serialization\access.hpp(118):
error C2039: ‘serialize’ : is not a
member of
‘ATL::CStringT’

In access.hpp it says

// note: if you get a compile time error here with a
// message something like:
// cannot convert parameter 1 from <file type 1> to <file type 2 &>
// a likely possible cause is that the class T contains a 
// serialize function - but that serialize function isn't 
// a template and corresponds to a file type different than
// the class Archive.  To resolve this, don't include an
// archive type other than that for which the serialization
// function is defined!!!

So I imagine that the CString has some serialization due to MFC.

Now I’m wondering, what can I do? Is there any workaround?
I’m trying to avoid the redefinition of the CStrings to std:string because there are so many of them, that it implies to re do the entire project.

Also, I want to serialize a CArray but I’m getting the same type of error, that serialize is not a member of CArray.

EDIT:
The CString problem is fixed by adding

template<class Archive>
inline void serialize(Archive & ar, CString & s, const unsigned int file_version) {
    split_free(ar, s, file_version); 
}

I don’t know why the macro doesn’t work. However, I’m still facing problems with the CArray. I tried a simple solution

ar & make_nvp("CArray",myCArray); 

but that doesn’t create any XML. And then I tried to iterate over the array like this

for(int i=0; i < myCArray.GetCount(); i++) {
  MyClass* m = (MyClass*) myCArray.GetAt(i);      
  ar & BOOST_SERIALIZATION_NVP(m);
}

but that isn’t calling the serialization of the class. Is there any straight forward way to serialize arrays like the std::vector or std::list in the Boost examples?

  • 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-05-19T13:30:46+00:00Added an answer on May 19, 2026 at 1:30 pm

    You can only use save and load if you are working with a class you can add BOOST_SERIALIZATION_SPLIT_MEMBER() to the definition of. Since you can’t do that for string, you need to implement Boost serialization in terms of a serialize method:

    template<class Archive>
    void serialize(Archive & ar, CString & s, const unsigned int version)
    {
        std::string ss(s);
        ar & ss;
        s = ss.c_str;
    }
    

    This is less efficient, but it should at least compile.

    EDIT: Actually, you can split a free function, but you need to add this along with your save and load functions:

    #include <boost/serialization/split_free.hpp>
    
    template<class Archive>
    inline void serialize(Archive & ar, CString & s, const unsigned int file_version) {
        split_free(ar, s, file_version); 
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I am trying to understand how to use SyndicationItem to display feed which is
I've got a string that has curly quotes in it. I'd like to replace
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to create an if statement in PHP that prevents a single post
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the

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.