c++ - boost::property_tree 编译错误(错误 C2061:语法错误:标识符 'p')

标签 c++ boost boost-propertytree

我正在努力编译一些利用 boost 属性树的代码。我正在使用 Visual Studio 2010。

如果我尽可能地简化代码以重现错误,则代码如下所示...

#include "AppleiTunesLibraryImporter.h"
#include <boost/property_tree/xml_parser.hpp>
#include <boost/property_tree/ptree.hpp>
using namespace boost::property_tree;

AppleiTunesLibraryImporter::AppleiTunesLibraryImporter(){}
AppleiTunesLibraryImporter::~AppleiTunesLibraryImporter(){}

bool AppleiTunesLibraryImporter::ImportData( std::string itunes_library_xml_path )
{
    ptree pt;
    xml_parser::read_xml( itunes_library_xml_path.c_str(), pt, xml_parser::no_comments | xml_parser::trim_whitespace);
    return true;
}

...完整的错误如下所示...

1>  AppleiTunesLibraryImporter.cpp
1>c:\<path to my file>\thirdparty\boost\boost-1.47.0\boost/detail/allocator_utilities.hpp(178): error C2061: syntax error : identifier 'p'
1>          c:\<path to my file>\thirdparty\boost\boost-1.47.0\boost/multi_index/detail/index_base.hpp(88) : see reference to function template instantiation 'void boost::detail::allocator::construct<T>(void *,const Type &)' being compiled
1>          with
1>          [
1>              T=std::pair<const std::string,boost::property_tree::basic_ptree<std::string,std::string>>,
1>              Type=std::pair<const std::string,boost::property_tree::basic_ptree<std::string,std::string>>
1>          ]
1>          c:\<path to my file>\thirdparty\boost\boost-1.47.0\boost/multi_index/detail/index_base.hpp(87) : while compiling class template member function 'boost::multi_index::detail::index_node_base<Value,Allocator> *boost::multi_index::detail::index_base<Value,IndexSpecifierList,Allocator>::insert_(const std::pair<_Ty1,_Ty2> &,boost::multi_index::detail::index_node_base<Value,Allocator> *)'
1>          with
1>          [
1>              Value=std::pair<const std::string,boost::property_tree::basic_ptree<std::string,std::string>>,
1>              Allocator=std::allocator<std::pair<const std::string,boost::property_tree::basic_ptree<std::string,std::string>>>,
1>              IndexSpecifierList=boost::multi_index::indexed_by<boost::multi_index::sequenced<>,boost::multi_index::ordered_non_unique<boost::multi_index::tag<boost::property_tree::basic_ptree<std::string,std::string>::subs::by_name>,boost::multi_index::member_offset<std::pair<const std::string,boost::property_tree::basic_ptree<std::string,std::string>>,const std::basic_string<char,std::char_traits<char>,std::allocator<char>>,0>,std::less<std::string>>>,
1>              _Ty1=const std::string,
1>              _Ty2=boost::property_tree::basic_ptree<std::string,std::string>
1>          ]
1>          c:\<path to my file>\thirdparty\boost\boost-1.47.0\boost/multi_index/ordered_index.hpp(119) : see reference to class template instantiation 'boost::multi_index::detail::index_base<Value,IndexSpecifierList,Allocator>' being compiled
1>          with
1>          [
1>              Value=std::pair<const std::string,boost::property_tree::basic_ptree<std::string,std::string>>,
1>              IndexSpecifierList=boost::multi_index::indexed_by<boost::multi_index::sequenced<>,boost::multi_index::ordered_non_unique<boost::multi_index::tag<boost::property_tree::basic_ptree<std::string,std::string>::subs::by_name>,boost::multi_index::member_offset<std::pair<const std::string,boost::property_tree::basic_ptree<std::string,std::string>>,const std::basic_string<char,std::char_traits<char>,std::allocator<char>>,0>,std::less<std::string>>>,
1>              Allocator=std::allocator<std::pair<const std::string,boost::property_tree::basic_ptree<std::string,std::string>>>
1>          ]
1>          c:\<path to my file>\thirdparty\boost\boost-1.47.0\boost/multi_index/sequenced_index.hpp(77) : see reference to class template instantiation 'boost::multi_index::detail::ordered_index<KeyFromValue,Compare,SuperMeta,TagList,Category>' being compiled
1>          with
1>          [
1>              KeyFromValue=boost::multi_index::member_offset<std::pair<const std::string,boost::property_tree::basic_ptree<std::string,std::string>>,const std::basic_string<char,std::char_traits<char>,std::allocator<char>>,0>,
1>              Compare=std::less<std::string>,
1>              SuperMeta=boost::multi_index::detail::nth_layer<2,std::pair<const std::string,boost::property_tree::basic_ptree<std::string,std::string>>,boost::multi_index::indexed_by<boost::multi_index::sequenced<>,boost::multi_index::ordered_non_unique<boost::multi_index::tag<boost::property_tree::basic_ptree<std::string,std::string>::subs::by_name>,boost::multi_index::member_offset<std::pair<const std::string,boost::property_tree::basic_ptree<std::string,std::string>>,const std::basic_string<char,std::char_traits<char>,std::allocator<char>>,0>,std::less<std::string>>>,std::allocator<std::pair<const std::string,boost::property_tree::basic_ptree<std::string,std::string>>>>,
1>              TagList=boost::mpl::vector1<boost::property_tree::basic_ptree<std::string,std::string>::subs::by_name>,
1>              Category=boost::multi_index::detail::ordered_non_unique_tag
1>          ]
1>          c:\<path to my file>\thirdparty\boost\boost-1.47.0\boost/multi_index_container.hpp(89) : see reference to class template instantiation 'boost::multi_index::detail::sequenced_index<SuperMeta,TagList>' being compiled
1>          with
1>          [
1>              SuperMeta=boost::multi_index::detail::nth_layer<1,std::pair<const std::string,boost::property_tree::basic_ptree<std::string,std::string>>,boost::multi_index::indexed_by<boost::multi_index::sequenced<>,boost::multi_index::ordered_non_unique<boost::multi_index::tag<boost::property_tree::basic_ptree<std::string,std::string>::subs::by_name>,boost::multi_index::member_offset<std::pair<const std::string,boost::property_tree::basic_ptree<std::string,std::string>>,const std::basic_string<char,std::char_traits<char>,std::allocator<char>>,0>,std::less<std::string>>>,std::allocator<std::pair<const std::string,boost::property_tree::basic_ptree<std::string,std::string>>>>,
1>              TagList=boost::mpl::vector0<boost::mpl::na>
1>          ]
1>          c:\<path to my file>\thirdparty\boost\boost-1.47.0\boost/property_tree/detail/ptree_implementation.hpp(59) : see reference to class template instantiation 'boost::multi_index::multi_index_container<Value,IndexSpecifierList>' being compiled
1>          with
1>          [
1>              Value=std::pair<const std::string,boost::property_tree::basic_ptree<std::string,std::string>>,
1>              IndexSpecifierList=boost::multi_index::indexed_by<boost::multi_index::sequenced<>,boost::multi_index::ordered_non_unique<boost::multi_index::tag<boost::property_tree::basic_ptree<std::string,std::string>::subs::by_name>,boost::multi_index::member_offset<std::pair<const std::string,boost::property_tree::basic_ptree<std::string,std::string>>,const std::basic_string<char,std::char_traits<char>,std::allocator<char>>,0>,std::less<std::string>>>
1>          ]
1>          c:\<path to my file>\thirdparty\boost\boost-1.47.0\boost/property_tree/detail/ptree_implementation.hpp(182) : see reference to class template instantiation 'boost::property_tree::basic_ptree<Key,Data>::subs' being compiled
1>          with
1>          [
1>              Key=std::string,
1>              Data=std::string
1>          ]
1>          c:\<path to my file>\thirdparty\boost\boost-1.47.0\boost/property_tree/detail/ptree_implementation.hpp(182) : while compiling class template member function 'boost::property_tree::basic_ptree<Key,Data>::basic_ptree(void)'
1>          with
1>          [
1>              Key=std::string,
1>              Data=std::string
1>          ]
1>          ..\..\..\common\Source\AppleiTunesImporter\AppleiTunesLibraryImporter.cpp(24) : see reference to class template instantiation 'boost::property_tree::basic_ptree<Key,Data>' being compiled
1>          with
1>          [
1>              Key=std::string,
1>              Data=std::string
1>          ]

对我来说,我的 ApplieiTunesLibraryImporter.cpp 文件的第 24 行就是

ptree pt;

因此,编译器不喜欢我使用它。当我使用类似的东西时,我会遇到类似的错误

ptree::const_assoc_iterator assoc_iter;

但上面的代码是最简单的,我可以让错误发生。

导致编译错误的 boost 文件 (allocator_utilities.hpp) 中的代码如下所示,但对我来说非常神秘。

/* allocator-independent versions of construct and destroy */

template<typename Type>
void construct(void* p,const Type& t)
{
  new (p) Type(t);
}

如果有人想尝试重现,这里是 .h 代码。

class AppleiTunesLibraryImporter
{
public:

    AppleiTunesLibraryImporter();
    virtual ~AppleiTunesLibraryImporter();

    bool ImportData( std::string itunes_library_xml_path );

};

这一切都变成了一点大脑融化,所以如果有人能对此有所了解,我们将不胜感激。

干杯。

最佳答案

我发现了问题。我正在处理的项目使用预编译头文件,对于使用 boost 库的 .cpp 文件,我必须防止这种情况发生。换句话说,我必须右键单击 .cpp 文件然后...

Properties > Configuration Properties > C/C++ > Precompiled Headers

并将“Precompiled Headers”设置为“Not Using Precompiled Headers” 另外,去...

Properties > Configuration Properties > C/C++ > Advanced

并将“强制包含文件”设置为空。

关于c++ - boost::property_tree 编译错误(错误 C2061:语法错误:标识符 'p'),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11150014/

相关文章:

c++ - 运算符重载;必须是二元运算符(有 3 个参数)

linux - 无法使用 makefile 进行编译 - 未定义对 `boost::re_detail 的引用

c++ - Boost PTree 仅用于读取文件还是用于存储值?

c++ - 一个作家许多读者发行 map

c++ - 比较顺序无关紧要的两个容器

c++ - boost::interprocess::ptree 的前向声明

boost - 如何使用 boost 属性树获取 ini 文件的子部分内的属性?

c++ - 读取数据文件C++中的多个项目

C++ 将静态二维 double 组转换为 double **

c++ - 如何将 std::array 转换为 std::tuple?