【问题标题】:error C2660: 'std::allocator<char>::allocate': function does not take 2 arguments错误 C2660:'std::allocator<char>::allocate':函数不接受 2 个参数
【发布时间】:2021-08-14 12:03:49
【问题描述】:

代码:

#include <string>

#include <boost/format.hpp>

int main() {
    boost::format fmt;
    auto str = fmt % L"";
}

错误:

1>D:.conan\a9fe50\1\include\boost\format\alt_sstream_impl.hpp(261,1): 错误 C2660:“std::allocator::allocate”:函数不占用 2 个参数 1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30037\include\xmemory(838,65): 消息:参见“std::allocator::allocate”的声明 1>D:.conan\a9fe50\1\include\boost\format\alt_sstream_impl.hpp(228): 消息:编译类模板成员函数'int boost::io::basic_altstringbuf::overflow(int)' 1>
与 1> [ 1> Ch=char, 1>
tr=std::char_traits, 1> 分配=std::allocator 1> ] 1>D:.conan\a9fe50\1\include\boost\format\format_class.hpp(173): 消息:参见对类模板实例化的参考 'boost::io::basic_altstringbuf' 正在编译 1>
与 1> [ 1> Ch=char, 1>
tr=std::char_traits, 1> 分配=std::allocator 1> ] 1>D:\Documents\source\repos\ConsoleApplication3\ConsoleApplication3\ConsoleApplication3.cpp(6): 消息:参见对类模板实例化的参考 'boost::basic_format' 正在编译 1>Generating Code... 1>Done building project "ConsoleApplication3.vcxproj" -- 失败。

环境

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

我今天将 VC++ 从 16.9 升级到 16.10,然后编译失败。 它仅在我使用 std:c++latest 时发生,但与 'std:c++17' 一起工作正常。

【问题讨论】:

    标签: c++ visual-c++ boost visual-studio-2019 c++20


    【解决方案1】:

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

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

    附注

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

    【讨论】:

      【解决方案2】:

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

      【讨论】:

        【解决方案3】:

        您可以定义_HAS_DEPRECATED_ALLOCATOR_MEMBERS

        即使您选择了 C++20 标准进行编译,它也会重新启用 C++20 中已删除的“分配器内容”。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2022-11-24
          • 1970-01-01
          • 2013-03-26
          • 1970-01-01
          • 1970-01-01
          • 2018-09-14
          • 2013-11-18
          • 1970-01-01
          相关资源
          最近更新 更多