Boost 错误“结构没有名为‘序列化’的成员”,尽管结构已序列化

Lea*_*Cpp 2 boost boost-serialization

以下是我设计的结构和类,最终目标是使用 boost 序列化将值写入 xml 当我编译下面的代码时,我收到一个编译时错误(错误很大,我只是粘贴了它的最后一行这可能讨论了这个问题)

/boost_1_49_0/include/boost/serialization/access.hpp:118: 错误: 'class std::map, std::allocator >, std::map, std::allocator >, std::map, std::allocator >、IdInfo、std::less、std::allocator > >、std::allocator、std::allocator >、IdInfo> > >、std::less、std::allocator > >、std::allocator、std ::allocator >, std::map, std::allocator >, IdInfo, std::less, std::allocator > >, std::allocator, std::allocator >, IdInfo> > > > > >, std ::less、std::allocator > >、std::allocator、std::allocator >、std::map、std::allocator>、std::map、std::allocator>、IdInfo、std::less , std::allocator > >, std::allocator, std::allocator >, IdInfo> > >, std::less, std::allocator > >, std::allocator, std::allocator >, std::映射、std::allocator >、IdInfo、std::less、std::allocator > >、std::allocator、std::allocator >、IdInfo> > > > > > > >' 没有名为 'serialize' 的成员 make: *** [READER.exe] 错误 1

下面的 AssetReaderInfo clkass 实际上有一个成员序列化,但错误与它相矛盾。

我已经在所有类中定义了序列化,但它无法编译此外,我还没有指定主要的 cpp 代码,因为我认为它会增加混乱

你能提出什么问题吗?

struct IdInfo
{
    std::string m_milePost;
    std::string m_cellModemAlertExclusionList;

    public:
    IdInfo():m_milePost("milepost"),m_cellModemAlertExclusionList("dummyval"){};

    template<class archive>
    void serialize(archive& ar, const unsigned int version)
    {
        using boost::serialization::make_nvp;
         ar & make_nvp("values", m_milePost);
         ar & make_nvp("values", m_cellModemAlertExclusionList);
    }
};

class myReader {
 public:

    friend class boost::serialization::access;
   // Asset ID list
   typedef std::map< std::string,IdInfo > myMap;
   typedef std::map< std::string > mySet;
   struct ReaderInfo
   {
         mySet m_aSList;
         myMap m_pList;
         myMap m_eList;
         // WIU/BS type
         std::string m_Type;
         std::string m_topic;
         std::string m_lastSavedMsg;
         template <class archive>
         void serialize(archive& ar, const unsigned int version)
         {
           using boost::serialization::make_nvp;
            ar & make_nvp("values", m_topic);
            ar & make_nvp("values", m_Type);
            ar & make_nvp("values", m_eList);
            ar & make_nvp("values", m_pList);
         }

   };
    typedef std::map< std::string, ReaderInfo > GroupDataMap;
    GroupDataMap    m_GroupDataMap;

    template<class archive>
    void serialize(archive& ar, const unsigned int version)
    {
        using boost::serialization::make_nvp;
        ar & make_nvp("Group", m_GroupDataMap);
    } 
}

int main()
{
   myReader Reader;
   boost::archive::xml_oarchive xml(ofs);
   xml << boost::serialization::make_nvp("Connections", Reader);
}
Run Code Online (Sandbox Code Playgroud)

解决方案:

事实证明,我应该使用 std::map 将 /boost/serialization/map.hpp 包含为 iam

谢谢您的帮助

Lea*_*Cpp 6

事实证明,我应该使用 std::map 将 /boost/serialization/map.hpp 包含为 iam

#include /boost/serialization/map.hpp