Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/visual-studio-2010/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 将对象放入boost::property_树的正确方法是什么?_C++_Boost_Boost Propertytree - Fatal编程技术网

C++ 将对象放入boost::property_树的正确方法是什么?

C++ 将对象放入boost::property_树的正确方法是什么?,c++,boost,boost-propertytree,C++,Boost,Boost Propertytree,考虑以下示例: #include <boost\property_tree\ptree.hpp> #include <boost/any.hpp> typedef boost::property_tree::ptree PT; struct Foo { int bar; int egg; Foo(): bar(), egg() {} }; int main() { Foo foo; foo.bar = 5; PT p

考虑以下示例:

#include <boost\property_tree\ptree.hpp>
#include <boost/any.hpp>

typedef boost::property_tree::ptree PT;

struct Foo
{
    int bar;
    int egg;
    Foo(): bar(), egg() {}
};


int main()
{
    Foo foo;
    foo.bar = 5;
    PT pt;
    pt.put<Foo>("foo", foo);
    return 0;
}
#包括
#包括
typedef boost::property_tree::ptree PT;
结构Foo
{
int-bar;
内特蛋;
Foo():bar(),egg(){}
};
int main()
{
富富,;
foo.bar=5;
PT;
pt.put(“foo”,foo);
返回0;
}
我是boost新手,我愿意将一个Foo对象放入属性树中。上面的示例不会编译,但会出现错误:


c:\mingw\bin\../lib/gcc/mingw32/4.5.2/../../../../../../../../include/boost/property\u tree/stream\u translator.hpp:33:13:错误:与“operator”不匹配只需创建一个重载的
运算符。如果您有operator@NicolBolas当前位置是否有我遗漏的其他选项?我看不出有什么方法可以重载
操作符
ostream& operator<<(ostream& out, Foo output_object)
{
    out << egg << " " << bar;
    return out;
}
Foo test;
cout << test; //will print out whatever the values of "egg" and "bar" are