I’m writing some class which will act like a usual collection in QT:
class MyCollection
{
MyElement & at(int) const;
MyElement & operator[](int) const;
int count() const;
};
Now I want to enumerate all elements in my new class with QT’s foreach. What should I do to achieve this?
Qt (4.8 at least) uses (from
foreachmacro) a template wrapper classQForeachContainer(seeqglobal.h) to iterate over smth. Default implementation callsbegin()/end(), but you can write your own specialization as well… or just implementiterator begin(),iterator end()members