简体   繁体   English

错误 C2660: 'std::allocator<char> ::allocate': function 不占用 2 arguments</char>

[英]error C2660: 'std::allocator<char>::allocate': function does not take 2 arguments

Code:代码:

#include <string>

#include <boost/format.hpp>

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

Errors:错误:

1>D:.conan\a9fe50\1\include\boost\format\alt_sstream_impl.hpp(261,1): error C2660: 'std::allocator::allocate': function does not take 2 arguments 1>C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Tools\MSVC\14.29.30037\include\xmemory(838,65): message: see declaration of 'std::allocator::allocate' 1>D:.conan\a9fe50\1\include\boost\format\alt_sstream_impl.hpp(228): message: while compiling class template member function 'int boost::io::basic_altstringbuf<Ch,Tr,Alloc>::overflow(int)' 1> 1>D:.conan\a9fe50\1\include\boost\format\alt_sstream_impl.hpp(261,1): 错误 C2660: 'std::allocator::allocate': function 不占用 2 ZDBC11CAA5BDA99F77E6FB4DABD882ED7 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): message: while compiling class template member function 'int boost::io::basic_altstringbuf<Ch,Tr,Alloc>::overflow(int )' 1>
with 1> [ 1> Ch=char, 1>与 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): message: see reference to class template instantiation 'boost::io::basic_altstringbuf<Ch,Tr,Alloc>' being compiled 1> Tr=std::char_traits, 1> Alloc=std::allocator 1> ] 1>D:.conan\a9fe50\1\include\boost\format\format_class.hpp(173):消息:见参考 class 模板实例化'boost::io::basic_altstringbuf<Ch,Tr,Alloc>' 正在编译 1>
with 1> [ 1> Ch=char, 1>与 1> [ 1> Ch=char, 1>
Tr=std::char_traits, 1> Alloc=std::allocator 1> ] 1>D:\Documents\source\repos\ConsoleApplication3\ConsoleApplication3\ConsoleApplication3.cpp(6): message: see reference to class template instantiation 'boost::basic_format<char,std::char_traits,std::allocator>' being compiled 1>Generating Code... 1>Done building project "ConsoleApplication3.vcxproj" -- FAILED. Tr=std::char_traits, 1> Alloc=std::allocator 1> ] 1>D:\Documents\source\repos\ConsoleApplication3\ConsoleApplication3\ConsoleApplication3.cpp(6):消息:见参考 class 模板实例化'boost ::basic_format<char,std::char_traits,std::allocator>' 正在编译 1>Generating Code... 1>Done building project "ConsoleApplication3.vcxproj" -- 失败。

Environment环境

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

I upgraded VC++ today from 16.9 to 16.10, then compilation was broken.我今天将 VC++ 从 16.9 升级到 16.10,然后编译失败。 It only happens when I use std:c++latest , but works fine with 'std:c++17'.它仅在我使用std:c++latest时发生,但适用于“std:c++17”。

The library lacks c++20 support (see https://en.cppreference.com/w/cpp/memory/allocator/allocate )该库缺少 c++20 支持(请参阅https://en.cppreference.com/w/cpp/memory/allocator/allocate

You can, for now, opt for c++17 compilation.现在,您可以选择 c++17 编译。 Also, see whether they know about this issue, and if not report it to the developers.另外,看看他们是否知道这个问题,如果不知道,请向开发人员报告。

Side Notes旁注

  • I take it the sample is reduced, but it seems to me the literal ought to be narrow, or the fmt ought to be wformat我认为样本减少了,但在我看来字面应该是窄的,或者 fmt 应该是wformat
  • It appears that Boost 1.76 doesn't have this problem so, try upgrading boost看来 Boost 1.76 没有这个问题,所以尝试升级 boost

I realize this is a few months old now, but I just hit this same issue with boost 1.70 after upgrading VS 2019. All I did was remove the 2nd argument to the 'allocate' call on line 261 of alt_sstream_impl.hpp, since it's just a hint/optimization that was deprecated in c++ 17, and now gone in c++ 20. Fortunately, it's an inline method, so no linker issues.我意识到这已经几个月了,但是在升级 VS 2019 之后,我刚刚在 boost 1.70 中遇到了同样的问题。我所做的只是删除了 alt_sstream_impl.hpp 的第 261 行的“分配”调用的第二个参数,因为它只是在 c++ 17 中已弃用的提示/优化,现在在 c++ 20 中消失。幸运的是,它是一种内联方法,因此没有 linker 问题。

You can define _HAS_DEPRECATED_ALLOCATOR_MEMBERS您可以定义 _HAS_DEPRECATED_ALLOCATOR_MEMBERS

It will reenable the removed "allocator stuff" in C++20 even when you compile with C++20 standard selected.即使您使用选择的 C++20 标准进行编译,它也会重新启用 C++20 中已删除的“分配器内容”。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 C ++错误C2660:函数没有3个参数 - C++ Error C2660: Function does not take 3 arguments 奇怪的错误c2660“函数不带1个参数” - Strange error c2660 “function does not take 1 arguments” 错误C2660:函数没有2个参数C ++ - Error C2660: function does not take 2 arguments C++ 错误C2660:&#39;Aba :: f&#39;:函数未使用0个参数 - error C2660: 'Aba::f' : function does not take 0 arguments 错误C2660:&#39;MouseListener :: MousePressed&#39;:函数未采用4个参数 - error C2660: 'MouseListener::MousePressed' : function does not take 4 arguments 错误 C2660: 'std::pair<a,b> ::pair': function 不带 2 arguments</a,b> - error C2660: 'std::pair<a,b>::pair': function does not take 2 arguments 简短版本:错误14错误C2660:“ Player :: addSpell”:函数未采用1个参数 - Short version: Error 14 error C2660: 'Player::addSpell' : function does not take 1 arguments C ++中的特征库给出错误C2660:&#39;Eigen :: MatrixBase <Derived> :: eigenvalues&#39;:函数不带2个参数 - eigen library in C++ gives error C2660: 'Eigen::MatrixBase<Derived>::eigenvalues' : function does not take 2 arguments 如何解决“C2660 &#39;SWidget::Construct&#39;:函数不接受 1 个参数”? - How to resolve "C2660 'SWidget::Construct': function does not take 1 arguments"? 尝试在 windows 10 上安装 node-ffi 会出现错误:error C2660: 'v8::FunctionTemplate::GetFunction': function does not take 0 arguments - trying to install node-ffi on windows 10 gives error: error C2660: 'v8::FunctionTemplate::GetFunction': function does not take 0 arguments
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM