0
how to move classes into arrays without reconstructing
(*-*)
12 Réponses
0
i tried moving classes to arrays but got error,also moving classes to vectors will reconstruct them
0
the main problem that i dont want to initialize classes inside arrays or vectors but want to move them in
0
Theoretically, something like this should suffice:
https://code.sololearn.com/cD9KN7vIbsH5/?ref=app
But there is no point in speculating what might be an issue in your particular code, so you should link it here.
0
i didn't mean that array type,i meant the array with []
0
like: foo a[10]
0
i tried moving a class,got error
0
u dont understand me
0
i dont want them to reconstruct because the values of the current class will reset
0
look here
0
It doesn't matter whether you use std::array or a plain array, it should be the same. You could substitute the latter for std::array in my code and it would still work, since std::array only encapsulates a plain array.
Obviously the container value will not yield 6 in your code, you never assign that value to the constructed object in your move constructor. It is important to realize that a move constructor works a lot like a copy constructor, except that you operate under the assumption that the original object doesn't need to be preserved. If anything, you would have to write:
foo( foo&& other )
: val{ other.val }
{
cout << "&&constructor\n";
}
And yes, it is quite hard to understand you if you give such little information regarding your problem ("got error" - What error? What error message? Where is the code?) and fractured explanations on top of that.
0
got it