错误 C2660:"std::分配器::<char>分配":函数不接受 2 个参数



代码:

#include <string>
#include <boost/format.hpp>
int main() {
boost::format fmt;
auto str = fmt % L"";
}

错误:

1>D: .conan\a9fe50\1\include\boost\format\alt_stream_impl.hpp(261,1(:错误C2660:"std::allocater::allocate":函数不接受2个参数1>C: \Program Files(x86(\Microsoft VisualStudio\2019\Community\VC\Tools\MSVC\14.29.30037\include\xmemory(838,65(:消息:请参阅"std::allocater::allocate"的声明1>D: .conan\a9fe50\1\include\boost\format\alt_stream_impl.hpp(228(:消息:编译类模板成员函数"int"时boost::io::basic_altstringbuf<Ch,Tr,Alloc>:溢出(int('1>
带有1>[1>Ch=char,1>
Tr=std::char_traits,1>Alloc=std:;]1>D: .conan\a9fe50\1\include\boost\format\format_class.hpp(173(:消息:请参阅对类模板实例化的引用'boost::io::basic_altstringbuf<Ch,Tr,Alloc>'正在编译1>
带有1>[1>Ch=char,1>
Tr=std::char_traits,1>Alloc=std:;]1>D: \Documents\source\repos\ConsoleApplication3\ConsoleApplication 3\cpp(6(:消息:请参阅对类模板实例化的引用'boost::basic_format<char,std::char_traits,std::分配器>'正在编译1>正在生成代码。。。1>已完成建筑项目"控制台应用程序3.vcxproj"--失败。

环境

  • 操作系统:Win10-64bit
  • VC++2019 16.10.0
  • 配置:x86
  • SDK版本:10.0(最新安装版本(
  • 语言:std:c++最新
  • 升压:1.73

我今天将VC++从16.9升级到16.10,然后编译中断。只有当我使用std:c++latest时才会发生这种情况,但与"std:c++17"配合使用时效果良好。

该库缺乏对c++20的支持(请参阅https://en.cppreference.com/w/cpp/memory/allocator/allocate)

现在,您可以选择c++17编译。此外,看看他们是否知道这个问题,如果不知道,就向开发人员报告。

旁注

  • 我认为样本减少了,但在我看来,文字应该很窄,或者fmt应该是wformat
  • Boost 1.76似乎没有这个问题,所以,尝试升级Boost

我意识到这已经有几个月的历史了,但在升级VS 2019后,我刚刚遇到了同样的问题,提升了1.70。我所做的只是删除alt_stream_impl.hpp第261行"allocate"调用的第二个参数,因为它只是一个提示/优化,在c++17中被弃用,现在在c++20中消失了。幸运的是,它是一个内联方法,所以没有链接器问题。

您可以定义_HAS_DEPREATED_ALLOCATOR_MEMBERS

它将重新启用删除的";分配器的东西";在C++20中,即使使用选定的C++20标准进行编译。

最新更新