我有一个看起来像这样的类(class)成员
class Controller {
protected:
// other stuff
std::vector<Task<event_t, stackDepth>> taskHandlers;
//some more stuf
}
Task
类是 non-defaultConstructible、non-copyConstructible、non-copyAssignable 但是是 moveConstructible 和 moveAssignable。我能读到的所有内容(特别是 std::vector
文档)使我认为这应该可以编译,但错误列表如下所示(完整输出 here):/usr/include/c++/9/bits/stl_uninitialized.h:127:72: error: static assertion failed: result type must be constructible from value type of input range
127 | static_assert(is_constructible<_ValueType2, decltype(*__first)>::value,
| ^~~~~
制作 Task
defaultConstructible 没有帮助。错误指向类的定义Controller
.我在 c++17 模式下使用 GCC 9.3.0。我做错了什么吗?
最佳答案
根据当前的信息,我最好的猜测是你以某种方式弄乱了 move 构造函数的语法 - 仅使用 emplace_back
的工作示例:
下面编译正常,link to godbolt :
#include <vector>
class X
{
public:
X(int i) : i_(i){}
X() = delete;
X(const X&) = delete;
X(X&&) = default;//change this to 'delete' will give a similar compiler error
private:
int i_;
};
int main() {
std::vector<X> x;
x.emplace_back(5);
}
关于c++ - "result type must be constructible from value type of input range"创建 std::vector 时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62751522/