2009-06-10 93 views
2

我有一些我想要構建的代碼。該代碼使用boost :: ptr_map類來序列化某些對象。我有Visual Studio 2008與boost1.38,我得到編譯器的錯誤。我想知道其他人是否看到過這樣的事情。C++ Boost ptr_map序列化錯誤

C2039:「序列化」:是不是「的boost :: ptr_map」的成員

看起來像一些參考丟失,我不知道它是什麼,我沒有看到任何升壓/系列化/ ptr_map。我搜索了很多,沒有任何事情證明是可行的。我創建了一個示例代碼,在下面生成相同的錯誤

#include <fstream> 
#include <iostream> 


#include <boost/archive/text_oarchive.hpp> 
#include <boost/archive/text_iarchive.hpp> 
#include <boost/config.hpp> 

#include <boost/shared_ptr.hpp> 
#include <boost/ptr_container/ptr_map.hpp> 

#include <boost/serialization/string.hpp> 
#include <boost/serialization/version.hpp> 
#include <boost/serialization/split_member.hpp> 

using namespace std; 

class User 
{ 
    boost::ptr_map<std::string, string> ptrmap; 

public: 

    friend class boost::serialization::access; 

    template<class Archive> 
    void serialize(Archive & ar, const unsigned int version) 
    { 
     ar & ptrmap; 
    } 

    bool save(const std::string& filename) 
    { 
     ofstream ofs(filename.c_str()); 

     if(ofs.good() == false) 
     { 
      return false; 
     } 

     try 
     { 
      boost::archive::text_oarchive oa(ofs); 
      oa << (*this); 
     } 
     catch(...) 
     { 
      throw; 
     } 

     return true; 
    } 
}; 


int main() 
{ 
    User user; 
    user.save("C:\\test.db"); 
    return EXIT_SUCCESS; 
} 

任何幫助表示讚賞。

回答

2

看起來好像有一個boost/ptr_container/serialize_ptr_map.hpp,這對#include很重要。

0

也許有沒有序列化支持boost :: ptr_map? Boost庫並沒有完全連接。嘗試詢問助推郵件列表。

但是,編寫一個函數來序列化一個ptr_map應該很容易。

+0

我有這樣的代碼之前編譯成功,我相信這是使用Visual Studio 2005中即VC8編譯 我將它張貼升壓郵件列表上也 – Faheem 2009-06-10 21:52:35