我知道这不是默认的,也可能不是使用 Boost 属性树的首选方式。但似乎都需要创建命名指针树。所以我尝试了:
#include <boost/property_tree/ptree.hpp>
#include <iostream>
#include <string>
template <class T>
int append(T val)
{
std::cout << "hello";
return 0;
}
int main()
{
using boost::property_tree::ptree;
ptree pt;
pt.put("function-int-pointer", &append<int>);
(pt.get("function-int-pointer", NULL))(123);
// ^-- error C2064: term does not evaluate to a function taking 1 arguments
(pt.get<int(*)(int)>("function-int-pointer"))(123);
// ^-- error C2678: binary '>>' : no operator found which takes a left-hand
// operand of type 'std::basic_istream<_Elem,_Traits>' (or there is no
// acceptable conversion)
}
如果可能的话,我希望 tham 可以自动恢复(简单的.get()
not .get<T>
)
似乎它可以存储指向函数的指针(主要是我想使用它)。但我无法从中获取它们(所以我想知道如何将指针存储在 Boost 属性树中以便自动恢复?