0

I've written a class vecMatrix that wraps around std::vector to provide two-dimensional storage functionalities. However, while it's incredibly convenient to be able to write loops that sweep the data in an std::vector object as

std::vector<float> vec;
for (auto& val: vec) { /* do stuff to val*/}

I can't do it with my custom class. What kind of operator overload is required to be able to code the same way for vecMatrix?:

vecMatrix<float> mat;
for (auto& val: mat) { /* do stuff to val*/}
joaocandre
  • 1,621
  • 4
  • 25
  • 42

1 Answers1

1

You'll need to define member functions begin and end that return iterators to the range that your class represents (or you can define non members that take a reference to your class as arguments.

eerorika
  • 232,697
  • 12
  • 197
  • 326