Monday, 19 August 2013

How to allow range for loop on my class?

How to allow range for loop on my class?

I have a class like this:
class Foo {
private:
int a,b,c,d;
char bar;
public:
//constructors here
};
I wanna allow range-for loop on my class, e.g.
Foo foo {};
for(auto& f : foo) {
//f will be a specific order such as c,b,d,(int)bar,a
}
How can I achieve this? I was looking at iterator but don't know what are
the requirements for a range-for loop. (Please don't ask me to use array
or STL type)

No comments:

Post a Comment