【发布时间】:2020-08-29 17:26:07
【问题描述】:
请考虑以下代码:
struct no_copy {
int x_;
std::function<void()> f_;
template <typename F>
no_copy(int x, F&& f)
: x_{ x }, f_{ std::forward<F>(f) } {};
no_copy(const no_copy&) = delete;
no_copy& operator= (const no_copy&) = delete;
no_copy(no_copy&&) noexcept = default;
no_copy& operator= (no_copy&&) noexcept = default;
};
int main() {
auto nc = no_copy(1, []() {});
auto tuple_func = std::make_tuple(std::move(nc), 2);
return 0;
}
我正在尝试从具有std::funtion<void()> 成员的仅移动类型构造一个元组。在 Visual Studio 2017 下,此代码无法编译:
error C2440: '<function-style-cast>': cannot convert from 'initializer list' to '_Ttype'
note: No constructor could take the source type, or constructor overload resolution was ambiguous
如果我使复制构造函数= default 一切正常。我知道这与std::function 有关,但我不确定是什么问题。
谢谢。
【问题讨论】:
-
MSVC 2017 是有史以来漏洞最多的 MSVC。尽快升级到 2019 年。