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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T05:20:12+00:00 2026-05-20T05:20:12+00:00

I want to serialize a hash map to a file and de-serialize it later

  • 0

I want to serialize a hash map to a file and de-serialize it later on.

#include <boost/serialization/hash_map.hpp>
#include <boost/filesystem/fstream.hpp>
#include <hash_map>

class A: virtual public B {
 public:
     friend class boost::serialization::access;
     stdext::hash_map<std::string, myClass> myClassHashTable; 
     template <class Archive>
     void serialize(Archive &ar, const unsigned int version)
     {
        ar & myClassHashTable;
     }
};

void A::serializedToDisk()
{
      boost::filesystem::path finalPath(SOME_CONSTANT);
      // code to create  boost::filesystem::ifstream ofs object
      boost::archive::text_oarchive oa(ofs);
      oa << myClassHashTable;
}
void A::restoreFromDisk()
{
     boost::filesystem::path finalPath(SOME_CONSTANT);
    // code to create  boost::filesystem::ifstream ifs object
      boost::archive::text_iarchive ia(ifs);
      ia >> myClassHashTable;
}

But I am getting an error as –

error C2039: ‘serialize’ : is not a member of ‘stdext::hash_map<_Kty,_Ty>’

I searched online for this error but didn’t get much help. Also, I checked in my boost installation serialization/hash_map.hpp does have a serialize() function in it. The same code worked for serialization of std::deque. Can anyone tell me how should I change it to make it compile?

  • 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-20T05:20:13+00:00Added an answer on May 20, 2026 at 5:20 am

    First at all , insert #define BOOST_HAS_HASH in top of your code .

    This change your compilation error to :

    “error C2039: ‘resize’ : is not a member of ‘stdext::hash_map<_Kty,_Ty>’”. 😀

    Next, if you comment your restoring function, you’ll see your code WORK fine and output ! < Good >

    But the problem is about an incompatibility between compilers .
    Unfortunately, the implementation of hash_map is different in ‘MSVS’ and ‘GCC’ and the resize is one example of this difference .


    Next to resolve this new problem,
    just #include boost/serialization/map.hpp
    and comment s.resize(bucket_count); in hash_collections_load_imp.hpp ( where it error )

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

Sidebar

Related Questions

I want to Serialize the Hash-Map of Default Lazy-list code and store it in
I want to Serialize a 60mb file into XML but it gives me System
I want to serialize this class: public class CarDisplay { public string Name {
I want to serialize a class to xml and store that in a field
I want to serialize an object. I've got this basic class structure: class Controller
I have a class that I want to serialize to xml. The class looks
I want to serialize a Map with Jackson. The Date should be serialized as
I have created custom result class to serialize json data to xml. I want
I want serialize object to binary file using operator <<, but when I serialize,
Consider the following code. I want to specialize std::hash<> used in a Map ,

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.