尽管结构已序列化,但提升错误 "Structure has no member named 'serialize' "
Boost error "Structure has no member named 'serialize' " though the structure has serialize
下面是我设计的结构和class,最终目标是使用boost序列化将值写入xml
当我编译下面的代码时,出现编译时错误(错误很大,我只是粘贴了它的最后一行,这可能是在讨论这个问题)
/boost_1_49_0/include/boost/serialization/access.hpp:118: error: '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::map, std::allocator >, IdInfo, std::less, std::allocator > >, std::allocator, std::allocator >, IdInfo> > > > > > > > >' has no member named 'serialize'
make: *** [READER.exe] Error 1
下面的AssetReaderInfo clkass其实有一个成员serialize但是报错与之矛盾
我已经在所有 classes 中定义了序列化,但它无法编译
另外,我没有指定主要的 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);
}
解决方案:
It turns out that i should include /boost/serialization/map.hpp as iam using a std::map
感谢帮助
事实证明,我应该使用 std::map
包含 /boost/serialization/map.hpp 作为 iam
#include /boost/serialization/map.hpp
下面是我设计的结构和class,最终目标是使用boost序列化将值写入xml 当我编译下面的代码时,出现编译时错误(错误很大,我只是粘贴了它的最后一行,这可能是在讨论这个问题)
/boost_1_49_0/include/boost/serialization/access.hpp:118: error: '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::map, std::allocator >, IdInfo, std::less, std::allocator > >, std::allocator, std::allocator >, IdInfo> > > > > > > > >' has no member named 'serialize' make: *** [READER.exe] Error 1
下面的AssetReaderInfo clkass其实有一个成员serialize但是报错与之矛盾
我已经在所有 classes 中定义了序列化,但它无法编译 另外,我没有指定主要的 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);
}
解决方案:
It turns out that i should include /boost/serialization/map.hpp as iam using a std::map
感谢帮助
事实证明,我应该使用 std::map
包含 /boost/serialization/map.hpp 作为 iam#include /boost/serialization/map.hpp