以下程序
#include <vector>
#include <boost/range/join.hpp>
int main() {
std::vector<int> a{1, 2, 3};
std::vector<int> b{4, 5, 6};
boost::join(a, b);
}
使用以下命令行编译:
/GS /W4 /Zc:wchar_t /ZI /Gm /Od /sdl /Fd"x64\Debug\vc141.pdb" /Zc:inline /fp:precise /D "BOOST_LIB_TOOLSET=\"vc141\"" /D "_UNICODE" /D "UNICODE" /errorReport:prompt /WX- /Zc:forScope /RTC1 /Gd /MDd /std:c++latest /Fa"x64\Debug\" /EHsc /nologo /Za /Fo"x64\Debug\" /Fp"x64\Debug\Project11.pch" /diagnostics:classic
产生以下错误:
1>------ Build started: Project: Project11, Configuration: Debug x64 ------
1>Source.cpp
1>c:\boost\include\boost-1_64\boost\range\detail\join_iterator.hpp(252): error C3646: 'dereference': unknown override specifier
1>c:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.10.25017\include\xutility(622): note: see reference to class template instantiation 'boost::range_detail::join_iterator<std::_Vector_iterator<std::_Vector_val<std::_Simple_types<int>>>,std::_Vector_iterator<std::_Vector_val<std::_Simple_types<int>>>,int,int &,boost::range_detail::inner_demote_iterator_traversal_tag<boost::iterators::random_access_traversal_tag,boost::iterators::random_access_traversal_tag>::type>' being compiled
1>c:\boost\include\boost-1_64\boost\iterator\iterator_categories.hpp(119): note: see reference to class template instantiation 'std::iterator_traits<Iterator>' being compiled
1> with
1> [
1> Iterator=boost::range_detail::join_iterator<std::_Vector_iterator<std::_Vector_val<std::_Simple_types<int>>>,std::_Vector_iterator<std::_Vector_val<std::_Simple_types<int>>>,int,int &,boost::range_detail::inner_demote_iterator_traversal_tag<boost::iterators::random_access_traversal_tag,boost::iterators::random_access_traversal_tag>::type>
1> ]
1>c:\boost\include\boost-1_64\boost\range\iterator_range_core.hpp(156): note: see reference to class template instantiation 'boost::iterators::iterator_traversal<IteratorT>' being compiled
1> with
1> [
1> IteratorT=boost::range_detail::join_iterator<std::_Vector_iterator<std::_Vector_val<std::_Simple_types<int>>>,std::_Vector_iterator<std::_Vector_val<std::_Simple_types<int>>>,int,int &,boost::range_detail::inner_demote_iterator_traversal_tag<boost::iterators::random_access_traversal_tag,boost::iterators::random_access_traversal_tag>::type>
1> ]
1>c:\boost\include\boost-1_64\boost\range\iterator_range_core.hpp(436): note: see reference to class template instantiation 'boost::iterator_range_detail::pure_iterator_traversal<IteratorT>' being compiled
1> with
1> [
1> IteratorT=boost::range_detail::join_iterator<std::_Vector_iterator<std::_Vector_val<std::_Simple_types<int>>>,std::_Vector_iterator<std::_Vector_val<std::_Simple_types<int>>>,int,int &,boost::range_detail::inner_demote_iterator_traversal_tag<boost::iterators::random_access_traversal_tag,boost::iterators::random_access_traversal_tag>::type>
1> ]
1>c:\boost\include\boost-1_64\boost\range\join.hpp(45): note: see reference to class template instantiation 'boost::iterator_range<boost::range_detail::join_iterator<std::_Vector_iterator<std::_Vector_val<std::_Simple_types<int>>>,std::_Vector_iterator<std::_Vector_val<std::_Simple_types<int>>>,int,int &,boost::range_detail::inner_demote_iterator_traversal_tag<boost::iterators::random_access_traversal_tag,boost::iterators::random_access_traversal_tag>::type>>' being compiled
1>c:\users\rex\documents\visual studio 2017\projects\project11\project11\source.cpp(7): note: see reference to class template instantiation 'boost::range::joined_range<std::vector<int,std::allocator<_Ty>>,std::vector<_Ty,std::allocator<_Ty>>>' being compiled
1> with
1> [
1> _Ty=int
1> ]
1>c:\boost\include\boost-1_64\boost\range\detail\join_iterator.hpp(252): error C2059: syntax error: '('
1>c:\boost\include\boost-1_64\boost\range\detail\join_iterator.hpp(253): error C2334: unexpected token(s) preceding '{'; skipping apparent function body
1>c:\boost\include\boost-1_64\boost\range\detail\join_iterator.hpp(263): error C2061: syntax error: identifier 'difference_type'
1>c:\boost\include\boost-1_64\boost\range\detail\join_iterator.hpp(271): error C3646: 'distance_to': unknown override specifier
1>c:\boost\include\boost-1_64\boost\range\detail\join_iterator.hpp(271): error C2059: syntax error: '('
1>c:\boost\include\boost-1_64\boost\range\detail\join_iterator.hpp(272): error C2334: unexpected token(s) preceding '{'; skipping apparent function body
1>c:\boost\include\boost-1_64\boost\range\detail\join_iterator.hpp(299): error C2061: syntax error: identifier 'difference_type'
1>c:\boost\include\boost-1_64\boost\range\detail\join_iterator.hpp(321): error C2061: syntax error: identifier 'difference_type'
1>Done building project "Project11.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
我正在使用使用 MSVC2017(工具集 v141)编译的 Boost 1.64,但我不确定它如何导致这些错误。
第一个错误是在join_iterator.hpp(252)并且该行是
typename join_iterator::reference dereference() const
我不明白为什么编译器将dereference
其视为覆盖说明符。需要修复什么才能编译?
在尝试了一些变体后,我发现将平台工具集从 v141 切换到 v140(从 VS2015)确实允许程序编译。
那么这是否意味着这只是一个错误?