vendredi 27 juillet 2018

Assignment to an array of std::unique_ptr

2 ways to declare an array of std::unique_ptr:

struct MyStruct
{
    int x = 0;
}

std::unique_ptr<MyStruct[]> Arr1[10];
std::array<std::unique_ptr<MyStruct>, 10> Arr2;

// Arr1[0] = ?
// Arr2[0] = ?

What is the syntax to assign an object to such an array? (I tried several ways, using std::make_unique ..it didn't work. I tried an addition of std::move ..it didn't work). It seems I miss something. My reference.

Any of the two has benefits over the other?

Aucun commentaire:

Enregistrer un commentaire