Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/clojure/3.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::属性树编译错误(错误C2061:语法错误:标识符';p';)_C++_Boost_Boost Propertytree - Fatal编程技术网

C++ boost::属性树编译错误(错误C2061:语法错误:标识符';p';)

C++ boost::属性树编译错误(错误C2061:语法错误:标识符';p';),c++,boost,boost-propertytree,C++,Boost,Boost Propertytree,我正在努力编译一些使用boost属性树的代码。我正在使用VisualStudio2010 如果我尽可能简化代码以重现错误,代码如下所示 #include "AppleiTunesLibraryImporter.h" #include <boost/property_tree/xml_parser.hpp> #include <boost/property_tree/ptree.hpp> using namespace boost::property_tree; Appl

我正在努力编译一些使用boost属性树的代码。我正在使用VisualStudio2010

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

#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>          ]
因此,编译器不喜欢我使用它。当我使用类似于

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);
}
这一切都变成了一点大脑的融化,所以如果有人能对此有所了解,我们将不胜感激


干杯。

我找到问题了。我正在处理的项目使用了预编译的头文件,对于使用boostlibs的.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")
#pragma push_宏(“新”)
#未定义新
#包括
#包括
#pragma pop_宏(“新”)

我需要更多的代码-不要发布部分错误消息和部分代码,而是将您的问题归结为您可以发布完整代码的内容,以便我们可以重现错误。感谢您的回复,Zac。你说得对,我遗漏了一些有用的信息,所以我编辑了原始帖子,使其更加完整。谢谢。您应该尝试在不添加任何内容的情况下重现此问题,并提供一个可编译的代码段来重现此问题。对我来说,在gcc和boost 1.49I上工作得非常完美。我在mac(gcc 4.0)和LLVM上的代码编译非常好。是窗户让我伤心。通过“添加”,您是指xml_解析器的使用吗?
#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")