C++ 为什么在迭代器外观中会出现编译错误,这取决于我将Boost头包含在哪里?
我正在尝试将Boost合并到我现有的中型项目中。我有预编译头文件,<代码> STDAFX.H./C>,我保留了所有的C++ STDLIB <代码> >包括< /Cl>指令(加上一些Windows标题),以及许多C++ 为什么在迭代器外观中会出现编译错误,这取决于我将Boost头包含在哪里?,c++,visual-c++,boost,visual-studio-2015,C++,Visual C++,Boost,Visual Studio 2015,我正在尝试将Boost合并到我现有的中型项目中。我有预编译头文件, STDAFX.H./C>,我保留了所有的C++ STDLIB >包括< /Cl>指令(加上一些Windows标题),以及许多 .CPP文件,其中包括 STDAFX .H/COD>,其中 A.CPP < /代码>。它在第一行中包括stdafx.h,然后是该文件只需要的一些其他头文件。我想在A.cpp中使用boost::program_options,因此我在stdafx.h之后将其添加到包含列表中,因此A.cpp的顶部如下所示:
stdafx.h
,然后是该文件只需要的一些其他头文件。我想在A.cpp
中使用boost::program_options
,因此我在stdafx.h
之后将其添加到包含列表中,因此A.cpp
的顶部如下所示:
#include "stdafx.h"
#include <boost/program_options.hpp>
// more #includes
最可能的解释是,您的一个头文件缺少include-guard(或者include-guard有一个拼写错误),而实际上您两次包含了一些boost头文件。(并不是所有的boost头文件都单独有include-guard。我听说,你应该包括的那些文件都有,但有些文件只是出于“效率原因”没有。) 或者,您正在某个名称空间中包含boost,这是它无法真正保护自己的
此错误
'boost::iterators::detail::postfix\u increment\u result':太少的模板参数
正是我所期望的,如果它是某个模板定义,并且编译器第二次遇到该定义。最可能的解释是,缺少一个头文件(或者include-guard有一个输入错误)实际上你已经包含了两次一些boost头文件(并不是所有的boost头文件都单独包含include-guard。你应该包含的都有,但有一些只是因为“效率原因”没有
或者,您正在某个名称空间中包含boost,这是它无法真正保护自己的
此错误
“boost::iterators::detail::postfix\u increment\u result”:太少的模板参数
正是我所期望的,如果它是某个模板定义,并且编译器第二次遇到该定义。问题是,我在整个项目中只包含一次此头,当它包含在一个sou中时,它就不起作用了rce文件(.cpp
),它显然没有包含在任何地方,因此Boost头不可能包含多次。可能不是程序选项本身,但可能这个iterator\u facade
的问题是,如果在其他文件中包含其他Boost lib,它们也可能隐式包含它。好吧,我注意到,如果我在不包含include的情况下包含它之前,它运行得很好,所以问题一定在某个地方。我会继续查找。而且,关于预编译头的整个问题不应该是相关的。如果关闭预编译头/刷新缓存修复了问题,那么这只意味着缓存过时,这是构建系统的问题。我很抱歉d我打算放弃,我又浪费了几个小时,结果一事无成,除了意识到MSVC除了拒绝编译代码之外,还报告了一个ICE,我觉得这是不应该发生的。问题是,我在整个项目中只包含一次头文件,当它包含在源文件(.cpp
)中时,它就不起作用了,它显然没有包含在任何地方,因此Boost头不可能包含多次。可能不是程序选项本身,但可能这个iterator\u facade
的问题是,如果在其他文件中包含其他Boost lib,它们也可能隐式包含它。好吧,我注意到,如果我在不包含include的情况下包含它之前,它运行得很好,所以问题一定在某个地方。我会继续查找。而且,关于预编译头的整个问题不应该是相关的。如果关闭预编译头/刷新缓存修复了问题,那么这只意味着缓存过时,这是构建系统的问题。我很抱歉我要放弃了,我又浪费了几个小时,除了意识到MSVC除了拒绝编译代码之外,还报告了一个ICE,我觉得这是不应该发生的,我什么也没有得到。
Severity Code Description Project File Line
Error C2976 'boost::iterators::detail::postfix_increment_result': too few template arguments testProject C:\boost_1_59_0\boost\iterator\iterator_facade.hpp 789
Error C1903 unable to recover from previous error(s); stopping compilation testProject C:\boost_1_59_0\boost\iterator\iterator_facade.hpp 790
Error C2143 syntax error: missing ';' before '++' testProject C:\boost_1_59_0\boost\iterator\iterator_facade.hpp 790
Error C2059 syntax error: ',' testProject C:\boost_1_59_0\boost\iterator\iterator_facade.hpp 534
Error C2059 syntax error: ',' testProject C:\boost_1_59_0\boost\iterator\iterator_facade.hpp 541
Error C2059 syntax error: ',' testProject C:\boost_1_59_0\boost\iterator\iterator_facade.hpp 600
Error C2059 syntax error: ',' testProject C:\boost_1_59_0\boost\iterator\iterator_facade.hpp 606
Error C2059 syntax error: ',' testProject C:\boost_1_59_0\boost\iterator\iterator_facade.hpp 789
Error C4430 missing type specifier - int assumed. Note: C++ does not support default-int testProject C:\boost_1_59_0\boost\iterator\iterator_facade.hpp 790
Error C2433 'type': 'inline' not permitted on data declarations testProject C:\boost_1_59_0\boost\iterator\iterator_facade.hpp 790
Error C2888 'if_<T1,T2,T3>::type type': symbol cannot be defined within namespace 'iterators' testProject C:\boost_1_59_0\boost\iterator\iterator_facade.hpp 790
Error C2976 'boost::iterators::iterator_facade': too few template arguments testProject C:\boost_1_59_0\boost\iterator\iterator_facade.hpp 534
Error C2976 'boost::iterators::iterator_facade': too few template arguments testProject C:\boost_1_59_0\boost\iterator\iterator_facade.hpp 541
Error C2976 'boost::iterators::iterator_facade': too few template arguments testProject C:\boost_1_59_0\boost\iterator\iterator_facade.hpp 600
Error C2976 'boost::iterators::iterator_facade': too few template arguments testProject C:\boost_1_59_0\boost\iterator\iterator_facade.hpp 606
#include <boost/program_options.hpp>
1> INTERNAL COMPILER ERROR in 'C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\bin\CL.exe'
1> Please choose the Technical Support command on the Visual C++
1> Help menu, or open the Technical Support help file for more information