【发布时间】:2012-08-20 10:34:35
【问题描述】:
我正在为一个项目使用 Boost.PropertyTree,我想对 Key 和 Data 使用用户定义的类型,而不是 Boost 在 ptree typedef 中使用的 std::string。
但是,当我自己键入def basic_ptree 时,我得到以下编译器错误:
1> main.cpp
1>c:\boost_1_49_0\boost\property_tree\ptree.hpp(82): error C2027: use of undefined type 'boost::property_tree::path_of<Key>'
1> with
1> [
1> Key=int
1> ]
1> c:\users\mathias\documents\visual studio 2012\projects\testappern\testappern\main.cpp(10) : see reference to class template instantiation 'boost::property_tree::basic_ptree<Key,Data>' being compiled
1> with
1> [
1> Key=int,
1> Data=int
1> ]
1>c:\users\mathias\documents\visual studio 2012\projects\testappern\testappern\main.cpp(13): error C2664: 'boost::property_tree::basic_ptree<Key,Data>::add_child' : cannot convert parameter 1 from 'int' to 'const boost::type &'
1> with
1> [
1> Key=int,
1> Data=int
1> ]
1> Reason: cannot convert from 'int' to 'const boost::type'
1> The target type has no constructors
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
以下 sn-p 显示了我如何键入def basic_tree 并获取编译器错误的示例:
#include <iostream>
#include <boost\property_tree\ptree.hpp>
using namespace boost::property_tree;
typedef basic_ptree<int, int> IntTree;
int main(int argc, char* argv[])
{
IntTree tree;
IntTree child;
int index = 42;
tree.add_child(index, child);
return 0;
}
所以我的问题是,我如何正确地 typedef 它? 如果有兴趣,我正在运行 MSVC 2012。
提前致谢!
【问题讨论】:
-
与您的问题完全无关,但如果您希望代码可移植,则不应在包含路径中使用反斜杠。 VC++ 已经能够处理正斜杠很长时间了。
-
@JoachimPileborg 感谢您提醒我。这只是我创建的一个快速 sn-p,当我懒得自己输入整个路径时,Visual Studio 的自动完成使用正斜杠。
标签: c++ templates boost compiler-errors boost-propertytree