how to move classes into arrays without reconstructing | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

how to move classes into arrays without reconstructing

(*-*)

3rd May 2021, 8:19 PM
return 0;
return 0; - avatar
12 Answers
0
i tried moving classes to arrays but got error,also moving classes to vectors will reconstruct them
3rd May 2021, 8:20 PM
return 0;
return 0; - avatar
0
the main problem that i dont want to initialize classes inside arrays or vectors but want to move them in
3rd May 2021, 8:21 PM
return 0;
return 0; - avatar
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.
3rd May 2021, 9:48 PM
Shadow
Shadow - avatar
0
i didn't mean that array type,i meant the array with []
3rd May 2021, 10:37 PM
return 0;
return 0; - avatar
0
like: foo a[10]
3rd May 2021, 10:37 PM
return 0;
return 0; - avatar
0
i tried moving a class,got error
3rd May 2021, 10:38 PM
return 0;
return 0; - avatar
0
u dont understand me
3rd May 2021, 10:51 PM
return 0;
return 0; - avatar
0
i dont want them to reconstruct because the values of the current class will reset
3rd May 2021, 10:52 PM
return 0;
return 0; - avatar
0
look here
3rd May 2021, 10:52 PM
return 0;
return 0; - avatar
3rd May 2021, 10:52 PM
return 0;
return 0; - avatar
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.
4th May 2021, 7:03 AM
Shadow
Shadow - avatar
0
got it
4th May 2021, 8:22 AM
return 0;
return 0; - avatar