我努力編譯一些利用boost屬性樹的代碼。我使用Visual Studio 2010中boost :: property_tree編譯錯誤(錯誤C2061:語法錯誤:標識符'p')
如果我儘可能簡化代碼重現錯誤,代碼如下所示...
#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);
};
這一切都變成了一點腦融化,所以如果任何人都可以擺脫這一點,這將不勝感激。
乾杯。
我需要更多的代碼 - 而不是張貼部分錯誤消息和部分代碼,將問題歸結爲可以發佈完整代碼的東西,以便重現錯誤。 – Zac
感謝您的回覆,Zac。你是對的,我錯過了一些有用的信息,所以我編輯了原始文章使其更加完整。謝謝。 – gmcc051
您應該嘗試在沒有任何附加內容的情況下重現此內容,並提供一個可複製問題的單個可編譯片段。對我來說,http://ideone.com/FhfsS完美適用於gcc boost 1.49 – pmr