I have two classes, one of which comes from the other. I would like to highlight std:vectorwhich populates the derived class. The hard question is that I want it to call the move constructor, written in the base class.
Here is the code:
class Base{
public:
size_t size;
double* buff;
Base(size_t _size):size(_size){
buff = new double[size];
}
Base() = delete;
Base operator=(const Base&) = delete;
Base(const Base&) = delete;
Base(Base&& b):size(b.size), buff(b.buff){
b.buff = nullptr;
}
Base operator=(Base&& b){
size = b.size;
buff = b.buff;
b.buff = nullptr;
}
};
class Derive : public Base{
public:
Derive(size_t _size):Base(_size){};
Derive() = delete;
Derive operator=(const Derive&) = delete;
Derive(const Derive&) = delete;
Derive(Derive&& b):Base(move(b)){}
Derive operator=(Derive&& b){
Base::operator=(move(b));
}
};
vector<Derive> v(10, move(Derive(5)));
g ++ tells me
error: use of deleted function ‘Derive::Derive(const Derive&)’
{ ::new(static_cast<void*>(__p)) _T1(std::forward<_Args>(__args)...); }
and I don’t understand what I have to do.
source
share