Guest User

Untitled

a guest
Jun 24th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. class Elem;
  2. class ElemVec : public vector<Elem>
  3. {
  4. public:
  5. void foo();
  6. };
  7.  
  8. void ElemVec::foo()
  9. {
  10. BOOST_FOREACH(Elem& elem, *this)
  11. {
  12. // Do something with elem
  13. }
  14. return;
  15. }
  16.  
  17. error C2355: 'this' : can only be referenced inside non-static member functions
  18.  
  19. void ElemVec::foo()
  20. {
  21. ElemVec* This = this;
  22. BOOST_FOREACH(Elem& elem, *This)
  23. {
  24. // Do something with elem
  25. }
  26. return;
  27. }
  28.  
  29. #include <boost/foreach.hpp>
  30. using namespace std;
  31. struct xxx : std::vector<int>
  32. {
  33. void test()
  34. {
  35. BOOST_FOREACH(int x, *this)
  36. {
  37. }
  38. }
  39. };
  40.  
  41. int main(void) {
  42. xxx x;
  43. x.test();
  44. return 0;
  45. }
Add Comment
Please, Sign In to add comment