微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

错误 C2660:“std::allocator<char>::allocate”:函数不接受 2 个参数 附注

如何解决错误 C2660:“std::allocator<char>::allocate”:函数不接受 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_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>
with 1> [ 1> Ch=char,1>
tr=std::char_traits,1> Alloc=std::allocator 1> ] 1>D:.conan\a9fe50\1\include\boost\format\format_class.hpp(173): 消息:请参阅对类模板实例化的参考 'boost::io::basic_altstringbuf' 正在编译 1>
with 1> [ 1> Ch=char,1> Alloc=std::allocator 1> ] 1>D:\Documents\source\repos\ConsoleApplication3\ConsoleApplication3\ConsoleApplication3.cpp(6): 消息:请参阅对类模板实例化的参考 'boost::basic_format' 正在编译 1>生成代码... 1>完成构建项目 “ConsoleApplication3.vcxproj”——失败。

环境

  • 操作系统:Win10-64 位
  • 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++20 支持(请参阅 https://en.cppreference.com/w/cpp/memory/allocator/allocate

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

附注

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

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。