lundi 31 août 2015

How to move a unique_ptr?

I have this code:

unique_ptr<int[]> p1, fitness_data (new int[NewPerson->num_entries]);

...add data to fitness_data...

p1 = std::move(fitness_data); //Attempt 1 or...
p1(std::move(fitness_data)); //Attempt 2. Either attempt is commented. 

Both stop the program with exit code 139. My IDE, CLion gives the error

'unique_ptr::operator=(const unique_ptr &)' is deleted

I'm assuming that the error is referring to an attempt made to copy the pointer, But I need to move it.

I would appreciate any help. I would hate to have to move back to manually freeing memory again. Unfortunately, the version of OpenMP we are allowed to use does not get along with vectors.

Thanks, Daniel

Aucun commentaire:

Enregistrer un commentaire