问题描述
代码:
#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
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
with 1> [ 1> Ch=char,1> Alloc=std::allocator 1>
]
1>D:\Documents\source\repos\ConsoleApplication3\ConsoleApplication3\ConsoleApplication3.cpp(6):
消息:请参阅对类模板实例化的参考
'boost::basic_format
环境
- 操作系统: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