I finished reading Thomas Becker's "C++ Rvalue References". I have a couple questions on Rvalues and Rvalue references.
Suppose I have a simple array class:
template <class T>
MyArray
{
...
T* m_ptr; // Pointer to elements
size_t m_count; // Count of elements
};
Further suppose it provides:
#if(__cplusplus >= 201103L)
MyArray(MyArray&& t)
: m_ptr(std::move(t.m_ptr)), m_count(std::move(t.m_count))
{
t.m_ptr = NULL;
t.m_count = 0;
}
MyArray operator=(MyArray&& t)
{
std::swap(*this, t);
return *this;
}
#endif
Now, suppose I have a derived class that does not add new data members:
MyImprovedArray : public MyArray
{
...
};
What is required of MyImprovedArray
?
Does it need a MyImprovedArray(MyImprovedArray&&)
and MyImprovedArray& operator=(MyImprovedArray&&)
also? If so, does it only need to perform the base class std::move
? Or does it need to perform the std::swap
too?
MyImprovedArray(MyImprovedArray&& t)
: MyArray(t)
{
}