【发布时间】:2018-01-27 21:55:38
【问题描述】:
我想将向量的指针移动到我的 A 对象 (this) 的向量。我想这样做是因为我使用我的帮助向量(用于合并排序)并且我想要原始向量中的帮助向量的值。然而,我只想使用 1 个操作(因此应该通过移动来完成,不要复制元素)。
这是我使用的代码:
template<class T>
class A:public vector<T> {
public:
void fillAndMove();
vector<T> help;
}
template<class T>
void A<T>:fillAndMove() {
// Fill a help array with random values
help.resize(2);
help[0] = 5;
help[1] = 3;
// This line doesn't work
*this = move(help);
}
我收到以下错误:
no match for 'operator=' (operand types are 'A<int>' and 'std::remove_reference<std::vector<int, std::allocator<int> >&>::type {aka std::vector<int, std::allocator<int> >}')
我认为问题在于需要将帮助向量转换为 A 类对象,但我不知道该怎么做。谁能帮帮我?
【问题讨论】:
标签: c++ class c++11 vector move