c++ - std::promise<T> 其中 T 在 Visual Studio 2017 中必须是默认可构造的?

标签 c++

我正在尝试在 Visual Studio 2017 中编译以下代码:

#include <future>

int main()
{
    std::promise<std::reference_wrapper<int>> promise;
    (void)promise;
}

但是,我收到以下错误:

error C2512: 'std::reference_wrapper': no appropriate default constructor available

而它在 GCC 和 Clang 上编译得很好。

这是 Visual Studio 中的明确错误还是 std::promise 的有效实现?

最佳答案

看起来是一个 known issue在 MSVC 的标准库实现中。 更简单的复现场景:

#include <future>
struct NoDefaultCtor
{
    NoDefaultCtor() = delete;
};
int main() {
    std::promise<NoDefaultCtor> p;
    return 0;
}

关于c++ - std::promise<T> 其中 T 在 Visual Studio 2017 中必须是默认可构造的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49830864/

相关文章:

c++ - tictactoe 游戏没有运算符 "=="匹配这些操作数

c++ - 抛出新的 std::exception 与抛出 std::exception

c++ - 实例化结构模板时出现问题

c++ - makefile中汇编文件的生成

c++ - 为什么 C++ 参数作用域会影响命名空间内的函数查找?

c++ - 从 SDL 1.2 中的 RGB 值数组渲染像素?

c++ - 如何实现从其基类获取变量的构造函数?

c++ - 重复一段代码固定次数

javascript - 有没有办法使用 js-ctypes 自动管理 native 代码分配的内存?

c++ - OpenGL 4 核心配置文件、着色器和 MFC