supporting for each loop in classes
how can i add "for each" 开发者_开发问答support for my class in c++0x and visual studio 2010?
I think the best way would be to add iterator support, with begin()
and end()
functions. The ranged-based for-loop uses them, and this also gives your class the richer set of functionality iterators provide.
You must make the class support the IEnumerable Interface
http://msdn.microsoft.com/en-us/library/system.collections.ienumerable.aspx
精彩评论