I tried to create a single memory panel for my matrix class, because std::vector<std::vector<double>> did not give the performance that I wanted. So I decided to use a single 1d array. So I thought about using shared_ptr double for this.
Declare the variable I made:
std::shared_ptr<double> matrix;
To allocate memory for the declared shared pointer, I did:
matrix = std::make_shared<double []> (row*col);
Now, to access an element to assign something to a specific location in the matrix:
*(matrix + r*col + c) = 0.0;
It gives me an error saying
`error: no matches for 'operator +' (operand types: 'std :: shared_ptr' and 'size_t')
I thought we could use + for the pointer. Why does this not allow adding a scalar value to the index?
solti source share