0

We have these classes:

struct Intermediate : public std::array<double,3> {};

struct Vector3 : public Intermediate
{
   // ........more ctors.........

   // Modified move constructor (base class)
   Vector3(std::array<double,3> &&v) { ??????? }

   // ........more functionality...........
};

Is the "modified" move constructor act like original move constructor?

How can I implement the constructor? Is there another way than std::array::swap?

4

1 に答える 1

2

あなたはこれを行うことができます:

Vector3(std::array<double,3> &&v)
{ static_cast<std::array<double,3>&>(*this) = std::move(v); }

vこれは、の基本クラスに移動割り当てますthis

しかし、その移動コンストラクターはかなり無意味に思えます。あなたがmoveその配列をコピーするときはdouble、とにかくコピーを行います。doubleには移動セマンティクスがなく、コピー セマンティクスのみがありarray<double,N>、その中に配列が直接含まれているため、別のオブジェクトに移動することはできません。

于 2013-02-05T15:30:20.743 に答える