Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Elem;
- class ElemVec : public vector<Elem>
- {
- public:
- void foo();
- };
- void ElemVec::foo()
- {
- BOOST_FOREACH(Elem& elem, *this)
- {
- // Do something with elem
- }
- return;
- }
- error C2355: 'this' : can only be referenced inside non-static member functions
- void ElemVec::foo()
- {
- ElemVec* This = this;
- BOOST_FOREACH(Elem& elem, *This)
- {
- // Do something with elem
- }
- return;
- }
- #include <boost/foreach.hpp>
- using namespace std;
- struct xxx : std::vector<int>
- {
- void test()
- {
- BOOST_FOREACH(int x, *this)
- {
- }
- }
- };
- int main(void) {
- xxx x;
- x.test();
- return 0;
- }
Add Comment
Please, Sign In to add comment