boost::p roperty_tree 编译错误(错误 C2061:语法错误:标识符"p")
boost::property_tree compile error (error C2061: syntax error : identifier 'p')
>我正在努力编译一些利用提升属性树的代码。我正在使用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>thirdpartyboostboost-1.47.0boost/detail/allocator_utilities.hpp(178): error C2061: syntax error : identifier 'p'
1> c:<path to my file>thirdpartyboostboost-1.47.0boost/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>thirdpartyboostboost-1.47.0boost/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>thirdpartyboostboost-1.47.0boost/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>thirdpartyboostboost-1.47.0boost/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>thirdpartyboostboost-1.47.0boost/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>thirdpartyboostboost-1.47.0boost/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>thirdpartyboostboost-1.47.0boost/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>thirdpartyboostboost-1.47.0boost/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> ......commonSourceAppleiTunesImporterAppleiTunesLibraryImporter.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;
但是上面的代码是我可以使错误发生的最简单的代码。
导致编译错误的提升文件(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文件...
并将"预编译头"属性>配置属性> C/C++> 预编译标头
设置为"不使用预编译头"另外,转到...
属性>配置属性> C/C++> 高级
并将"强制包含文件"设置为空。
我遇到了类似的问题,因为上面的解决方案不适用于我。我必须找到根本原因。当我发现它令我烦恼时,我意识到这不是我第一次:)进行这种调查。所以这次没有错误,在这里记录根本原因:)。我怀疑这与作者的根本原因相同。所以就我而言,问题是在作为预编译的一部分包含的标头中的某个地方有
#define new .... // Debugging memory leaks in debug
这个通过预编译标头的定义搞砸了放置新。
因为扔掉这个定义("政治"原因)是有问题的。我能找到的最好的方法
#pragma push_macro("new")
#undef new
#include <boost/property_tree/ptree.hpp>
#include <boost/property_tree/info_parser.hpp>
#pragma pop_macro("new")
相关文章:
- 为什么包含windows.h会产生语法错误,从而阻止类的实例化?(C2146,C2065)
- 错误 C2760:语法错误:映射迭代器上意外的标记"标识符",预期的";"
- 为什么我会收到错误 C2143 语法错误:缺少"*"之前的';'?
- 奇怪的代码抛出编译错误模板< J,int aSize=10> C2143:语法错误:在"<"之前缺少";"
- "错误 C0000:语法错误,令牌"<EOF>"处出现意外$end,并且不确定
- 我该怎么做才能摆脱使用命名空间时的语法错误?
- C++语法头文件错误
- 如何摆脱错误c2061;语法错误 cout?
- 语法错误:D3DX10Core 中的标识符'TEXTMETRICA'
- 错误 C2146:语法错误:标识符"A1"之前缺少","
- main.cpp(11):错误 C2059:语法错误:"字符串"
- 我想获取点的属性,它报告错误 C3867:"point::output_x":非标准语法;使用"&"创建指向成员的指针
- RedisGraph 语法错误在偏移量 8 靠近"创建"
- 如何修复此 FSM C++语法错误 C3867
- 函数错误 C2059:语法错误:'>'不起作用
- 为什么在main()之前断言会导致语法错误"error: expected ')' before numeric constant"?
- system() 返回错误语法错误:"("意外
- C++图形初始化错误(语法或丢失文件缺陷?
- 获取0:1(1):错误:语法错误,尝试编译着色器时意外$end
- Visual Studio错误:语法错误:标识符