0
我有一些代码在两台机器(Windows 8.1,msvs 2013,最新更新等和Windows 7 64位,msvs 2013,最新更新等)中编译得很好,并且SAME代码无法在另一台机器上编译(Windows 7 64位,msvs 2013,最新更新等 - 是的,就像一台工作机器一样)。所有机器都使用最新的平台工具集,项目文件与CMake文件生成的相同。msvs 2013错误C2057在一台计算机中,在另一台计算机上没有错误。这是怎么回事?
我试图找到它并尽可能使最小的项目,但示例项目编译罚款有问题的机器罚款。对于什么是值得的,下面是编译的例子,我在有问题的一行中添加了一条评论。
#include <functional>
#include <vector>
#include <cstdint>
template<class T>
bool container_value_equal(typename T::const_reference v0, typename T::const_reference v1) { return v0 == v1; }
template<class T>
bool unordered_intersection_exists(const T& v0,
const T& v1,
// The below line fails in the problem computer + application!
const std::function< bool(typename T::const_reference, typename T::const_reference)>& f = container_value_equal<T>);
int main()
{
const std::vector<size_t> * vec2 = nullptr;
std::vector<size_t> vec;
const auto& vec_cref = vec;
unordered_intersection_exists(vec_cref, *vec2);
return 0;
}
template<class T>
bool unordered_intersection_exists(const T& vec0,
const T& vec1,
const std::function< bool(typename T::const_reference, typename T::const_reference)>& f)
{
for (const auto& v0 : vec0)
for (const auto& v1 : vec1)
if (f(v0, v1))
return true;
return false;
}
与这其实那叫一个以上块的,唯一的区别是,代码位于静态库,而不是我预料到任何区别。 是为我的实际程序生成的错误有以下几种:
1>E:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\type_traits(1511): error C2057: expected constant expression
1> E:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\functional(385) : see reference to function template instantiation '_Ty std::forward<_Fty>(remove_reference<_Fty>::type &&) throw()' being compiled
1> with
1> [
1> _Ty=bool (__cdecl &)(T::const_reference,T::const_reference)
1> , _Fty=bool (__cdecl &)(T::const_reference,T::const_reference)
1> ]
1> E:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\functional(579) : see reference to function template instantiation 'void std::_Func_class<_Ret,const unsigned int &,const unsigned int &>::_Reset<_Fx(__cdecl &)>(_Fty)' being compiled
1> with
1> [
1> _Ret=bool
1> , _Fx=bool (T::const_reference,T::const_reference)
1> , _Fty=bool (__cdecl &)(T::const_reference,T::const_reference)
1> ]
1> E:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\include\functional(579) : see reference to function template instantiation 'void std::_Func_class<_Ret,const unsigned int &,const unsigned int &>::_Reset<_Fx(__cdecl &)>(_Fty)' being compiled
1> with
1> [
1> _Ret=bool
1> , _Fx=bool (T::const_reference,T::const_reference)
1> , _Fty=bool (__cdecl &)(T::const_reference,T::const_reference)
1> ]
1> E:\Programming\GitHub\xxx\yyy\zzz\ddd/eee/fff.h(14) : see reference to function template instantiation 'std::function<bool (const unsigned int &,const unsigned int &)>::function<bool(T::const_reference,T::const_reference)>(_Fx (__cdecl &))' being compiled
1> with
1> [
1> _Fx=bool (T::const_reference,T::const_reference)
1> ]
1> E:\Programming\GitHub\xxx\yyy\zzz\aaa\bbb\ccc.cpp(443) : see reference to function template instantiation 'std::function<bool (const unsigned int &,const unsigned int &)>::function<bool(T::const_reference,T::const_reference)>(_Fx (__cdecl &))' being compiled
1> with
1> [
1> _Fx=bool (T::const_reference,T::const_reference)
1> ]
确保您的'Configuration Properties - > General - > Platform Toolset'设置为'Visual Studio 2013'。 – PaulMcKenzie 2014-11-06 23:24:29
谢谢,它已经是 – Babis 2014-11-06 23:27:41
在[Property Manager](http://msdn.microsoft.com/en-us/library/669zx6zc.aspx)(不是Project Properties)中仔细检查默认includes和libs的顺序。这些属性会影响构建环境,并且*不会由项目文件带来。您可能会在一台机器上使用不同版本的Windows SDK。 – 2014-11-07 07:59:16