1

how can i add "for each" support for my class in c++0x and visual studio 2010?

GManNickG
  • 494,350
  • 52
  • 494
  • 543
user335870
  • 588
  • 2
  • 11
  • 22
  • 2
    Is there any particular reason you can't use STL containers instead of rolling your own? (Besides the misinformed bias against the STL) – Cogwheel Jun 29 '10 at 18:23

2 Answers2

5

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.

GManNickG
  • 494,350
  • 52
  • 494
  • 543
  • iterators is too slow (in game developing) and i don't want to use stl – user335870 Jun 29 '10 at 17:40
  • 11
    @user: I do game programming, and you're horribly mistaken. Program in assembly if you're that concerned, or learn to actually program C++. I'm actually surprised people still hold such ridiculous positions, I thought that C-to-C++ wave died out long ago. Program good solid C++, don't under-estimate your compiler, profile instead of guess, and move on. Use the standard library, it's there for a reason; I can't imagine how nasty your code must look without it. – GManNickG Jun 29 '10 at 17:49
-2

You must make the class support the IEnumerable Interface

http://msdn.microsoft.com/en-us/library/system.collections.ienumerable.aspx

Andrey
  • 1,247
  • 11
  • 30