我正在尝试从 XML 文件加载一个简单的类,但出现以下错误:
error: no match for 'operator>>' in 'xml >> boost::serialization::make_nvp(const
char*, T&) [with T = Options](((Options&)(& o)))'
我做错了一定是愚蠢的,但我不知道是什么。有人有想法吗?这是我的代码:
#include <fstream>
#include <boost/serialization/string.hpp>
#include <boost/serialization/map.hpp>
#include <boost/archive/xml_oarchive.hpp>
#include <boost/serialization/nvp.hpp>
class Options {
public:
Options() {
SetInteger("screenWidth", 1024);
SetInteger("screenHeight", 768);
}
void SetInteger(const std::string& name, int value) {
integers_[name] = value;
}
private:
std::map<std::string, int> integers_;
friend class boost::serialization::access;
template<class archive>
void serialize(archive& ar, const unsigned int version)
{
using boost::serialization::make_nvp;
ar & make_nvp("integers", integers_);
}
};
int main() {
Options o;
std::ofstream ifs("input.xml");
boost::archive::xml_oarchive xml(ifs);
xml >> boost::serialization::make_nvp("options", o); // error
}