Okay so say I have this.
1 2 3
|
std::unique_ptr<int> Blocks[10];
Blocks[0] = std::unique_ptr<int> (new int)
|
then I would like to do something equivalent to this
Last edited on
12 as in memory address or value ?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
|
#include <iostream>
#include <memory>
int main(){
std::unique_ptr<int> Blocks[10];
// for assigning value
Blocks[0] = std::unique_ptr<int>( new int( 12 ) );
// for assigning to address
Blocks[1] = std::unique_ptr<int>( (int*)12 );
return 0;
}
|
you need to cast them to unique_ptr before assigning it
Last edited on
Okay fixed my own problem, I thought it wasn't working cause when I went:
it equalled 1.
but then I went
it equalled 12, just wasn't thinking
EDIT: oops I wrote this before I refreshed the page and saw your replies, Thanks anyway though :)
Last edited on
SEGFAULT ?
The program crashes ???
I don't know I never try ...
I guess that mustn't be done...