I want to create a std::vector<float> vpd
which will be a reference to float*
.
float * old = new float[6];
for (int i = 0; i < 6; i++)
{
old[i] = i;
}
vector<float> vpd(6);
auto refasd = &*vpd.begin();
*refasd = *old;
vpd[0] = 23;
cout << old[0] << endl;
How should I modify the code, if I want get 23
from cout
?
You can't. std::vector
is not designed to take ownership of a raw pointer.
Maybe you can make do with std::unique_ptr<float[]>
, but the better solution is to directly use std::vector
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With