I have a field defined as
const vector<record>* data;
where record is defined as
const unique_ptr<vector<float>> features;
const float label;
In my main code, I use
vector<record>::iterator iter = data->begin()
The compiler isn't happy with my code with the no viable overloaded '=' error at that iterator assignment line. It also produces this warning:
/Library/Developer/CommandLineTools/usr/bin/../include/c++/v1/iterator:1097:7: note: candidate function (the implicit copy assignment operator) not viable: no known conversion from '__wrap_iter<const_pointer>' to 'const __wrap_iter<class MLx::Example *>' for 1st argument
What am I doing wrong?
"an iterator should be lightweight and should now own the data, i.e. there should be no attempt to copy or even touch record when I make the assignment."
It has nothing to do with the iterator would own the data stored in data data
, but the const unique_ptr<>
, restricts accessing the template argument types only as const
instances.
This means in turn, you need to use
vector<record>::const_iterator iter = data->begin();
// ^^^^^^
in your main code.
It's much like writing
const vector<record>* data;
As @Jonathan Potter mentioned in his comment
auto iter = data->begin();
should work as well.
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