title: BOOST_FOREACH: What is the error on using this of a STL container?
body: <p>Does anyone know why the following generates an error on VC9?</p>
  
  <pre><code>class Elem;
  class ElemVec : public vector&lt;Elem&gt;
  {
      public:
          void foo();
  };
  
  void ElemVec::foo()
  {
      BOOST_FOREACH(Elem&amp; elem, *this)
      {
          // Do something with elem
      }
      return;
  }
  </code></pre>
  
  <p>The error I get is:</p>
  
  <pre><code>error C2355: 'this' : can only be referenced inside non-static member functions
  </code></pre>
  
  <p>The only (hack) solution I have right now which compiles without error is:</p>
  
  <pre><code>void ElemVec::foo()
  {
      ElemVec* This = this;
      BOOST_FOREACH(Elem&amp; elem, *This)
      {
          // Do something with elem
      }
      return;
  }
  </code></pre>