This is just for learning purposes, I know I can just use a vector but I have
const int N = 1e3;
auto my_arr = std::make_unique<std::array<int, N>>();
// To access it I have to do this - why [0][0] twice?
my_arr.get()[0][0] = 1;
// Getting the size for fun
std::cout << sizeof(my_arr.get()) << "\n"; // outputs 8
std::cout << sizeof(my_arr.get()[0]) << "\n"; // outputs 800000000
std::cout << sizeof(my_arr.get()[0][0]) << "\n"; // outputs 8
I understand that .get() returns a pointer to the managed object but I don't understand why I need to do my_arr.get()[0][0] twice?
my_arr.get()returns a pointer. Dereferencing a pointer and indexing it at position 0 are the same thing.ptr[0]is defined to be the same at*(ptr + 0)my_arr.get()[0]is the same as*(my_arr.get()). You should use the latter because there's nomy_arr.get()[1].const int N = 1e3;? That looks kind of weird. Also remember thatstd::unique_ptris a replacement for a pointer, so strictly speaking you'll get a pointer to a pointer decayed from an array, and you'll end up with more or lesssizeof(int).*my_arrwithout get