我在尝试使用boost.multiprecision在我的VC2017项目中工作时遇到了问题,并且我尝试将最简单的项目作为概念证明:
{
msg = "You have insufficient funds in your Stripe account for this transfer. Your ACH balance is too low. You can use the the /v1/balance endpoint to view your Stripe balance (for more details, see stripe.com/docs/api#balance).";
status = 0;
}
不幸的是,此代码无法编译,并出现以下错误:
#include<boost/multiprecision/cpp_int.hpp>
int main() {
boost::multiprecision::cpp_int val{ 5 };
val *= 5;
val *= 5;
return val.convert_to<int>();
}
这些是我在最初使用boost.multiprecision的更复杂项目中遇到的完全相同的错误。我在Visual Studio 2015中编译代码没有任何问题。有没有人知道什么是错的,我需要做些什么来解决它?
使用boost.asio编译的项目没有问题:
1>------ Build started: Project: Multiprecision Test, Configuration: Debug x64 ------
1>Multi Main.cpp
1>Unknown compiler version - please run the configure tests and report the results
1>g:\workspacec\solutions\project4x\library\include\boost\utility\compare_pointees.hpp(36): error C2143: syntax error: missing ',' before '<'
1>g:\workspacec\solutions\project4x\library\include\boost\utility\compare_pointees.hpp(40): note: see reference to class template instantiation 'boost::equal_pointees_t<OptionalPointee>' being compiled
1>g:\workspacec\solutions\project4x\library\include\boost\utility\compare_pointees.hpp(59): error C2143: syntax error: missing ',' before '<'
1>g:\workspacec\solutions\project4x\library\include\boost\utility\compare_pointees.hpp(63): note: see reference to class template instantiation 'boost::less_pointees_t<OptionalPointee>' being compiled
1>g:\workspacec\solutions\project4x\library\include\boost\numeric\conversion\detail\converter.hpp(453): error C2143: syntax error: missing ',' before '<'
1>g:\workspacec\solutions\project4x\library\include\boost\numeric\conversion\detail\converter.hpp(467): note: see reference to class template instantiation 'boost::numeric::convdetail::trivial_converter_impl<Traits>' being compiled
1>g:\workspacec\solutions\project4x\library\include\boost\numeric\conversion\detail\converter.hpp(453): error C2518: keyword 'typename' illegal in base class list; ignored
1>g:\workspacec\solutions\project4x\library\include\boost\numeric\conversion\detail\converter.hpp(454): error C2518: keyword 'typename' illegal in base class list; ignored
1>g:\workspacec\solutions\project4x\library\include\boost\numeric\conversion\detail\converter.hpp(474): error C2143: syntax error: missing ',' before '<'
1>g:\workspacec\solutions\project4x\library\include\boost\numeric\conversion\detail\converter.hpp(497): note: see reference to class template instantiation 'boost::numeric::convdetail::rounding_converter<Traits,RangeChecker,RawConverter,Float2IntRounder>' being compiled
1>g:\workspacec\solutions\project4x\library\include\boost\numeric\conversion\detail\converter.hpp(474): error C2518: keyword 'typename' illegal in base class list; ignored
1>g:\workspacec\solutions\project4x\library\include\boost\numeric\conversion\detail\converter.hpp(475): error C2518: keyword 'typename' illegal in base class list; ignored
1>g:\workspacec\solutions\project4x\library\include\boost\numeric\conversion\detail\converter.hpp(504): error C2143: syntax error: missing ',' before '<'
1>g:\workspacec\solutions\project4x\library\include\boost\numeric\conversion\detail\converter.hpp(526): note: see reference to class template instantiation 'boost::numeric::convdetail::non_rounding_converter<Traits,RangeChecker,RawConverter>' being compiled
1>g:\workspacec\solutions\project4x\library\include\boost\numeric\conversion\detail\converter.hpp(504): error C2518: keyword 'typename' illegal in base class list; ignored
1>g:\workspacec\solutions\project4x\library\include\boost\numeric\conversion\detail\converter.hpp(505): error C2518: keyword 'typename' illegal in base class list; ignored
1>Done building project "Multiprecision Test.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 2 up-to-date, 0 skipped ==========
答案 0 :(得分:15)
问题是由boost::multiprecision
中的某些模板使用std::unary_function
引起的,该模板自C ++ 11以来已被弃用,并已从C ++ 17的标准中删除。
MSVC 2015中的标准库实现引入了诸如#if _HAS_AUTO_PTR_ETC
之类的保护,围绕这些已弃用的定义。默认情况下,它们在新开关1
(默认值)下设置为/std:c++14
,默认情况下设置为0
/std:c++latest
(新编译器开关自2015年更新后可用) 3)。
因此,在boost删除std::unary_function
上的依赖项之前,您必须不使用/std:c++latest
(我一直在使用它,因为它出来了)或#define _HAS_AUTO_PTR_ETC 1
之前包括({1}}直接或间接)任何标准库头。因此,要么使用编译器选项设置,要么在某些PCH中设置,这是第一个包含在所有翻译单元或类似内容中的PCH。
这些设置的详尽说明,包括控制其他已弃用或已删除功能的其他警卫,可以在Stephan T. Lavavej的this blog post中找到。 Visual C++ change history 2003 - 2015似乎是MSVC中突破性变化的官方列表,但遗憾的是它并未涵盖所有这些细节。一般来说,扫描来自Stephan的帖子的Visual C++ Team Blog将为您提供有关这些内容的最佳信息。