title: Using lambda function to modify class
body: <p>I am currently trying to use <code>std::transform()</code> on a vector that contains smart pointers to a class named <code>Triangle</code>, in which I have several methods that change <code>Triangle</code> parameters.</p>
  
  <p>Now I want to make my life easier and use <code>std::transform()</code> with my own lambda function and apply it to every dynamically allocated triangle.</p>
  
  <p>However, I ran into a problem when trying to access private attributes of my class inside that very lambda function.
  I am curious how can I overcome this issue?</p>
  
  <pre><code>typedef std::pair&lt;double, double&gt; Point;
  
  //the class Triangle contains these methods:
  
  class Triangle{
      Point t1, t2, t3;
  public:
      Trougao(const Point &amp;t1, const Point &amp;t2, const Point &amp;t3){
          if(Triangle::Orijentacija(t1,t2,t3)==0) 
              throw std::domain_error("Incorrect vertices");
          Triangle::t1.first=t1.first;
          Triangle::t1.second=t1.second;
          Triangle::t2.first=t2.first;
          Triangle::t2.second=t2.second;
          Triangle::t3.first=t3.first;
          Triangle::t3.second=t3.second;
      }
  
      void Set(const Point &amp;t1, const Point &amp;t2, const Point &amp;t3){
          if(Triangle::Orientation(t1,t2,t3)==0)
              throw std::domain_error("Incorrect vertices");
          Triangle::t1.first=t1.first;
          Triangle::t1.second=t1.second;
          Triangle::t2.first=t2.first;
          Triangle::t2.second=t2.second;
          Triangle::t3.first=t3.first;
          Triangle::t3.second=t3.second;
      }
  
      void Set(int indeks, const Point &amp;t){
          if(indeks!=1 &amp;&amp; indeks!=2 &amp;&amp; indeks!=3)
              throw std::range_error("Incorrect index");
          if(indeks==1){
              this-&gt;t1.first=t.first;
              this-&gt;t1.second=t.second;
          }
          else if(indeks==2){
              this-&gt;t2.first=t.first;
              this-&gt;t2.second=t.second;
          }
          else if (indeks==3){
              this-&gt;t3.first=t.first;
              this-&gt;t3.second=t.second;
          }
      }
  
      Point GiveVertex(int indeks) const{
          if(indeks!=1 &amp;&amp; indeks!=2 &amp;&amp; indeks!=3)
              throw std::range_error("Incorrect index");
          if(indeks==1) return Triangle::t1;
          else if(indeks==2) return Triangle::t2;
          else if(indeks==3) return Triangle::t3;
      }
  
      void Translate(double delta_x, double delta_y){
          t1.first+=delta_x;
          t1.second+=delta_y;
          t2.first+=delta_x;
          t2.second+=delta_y;
          t3.first+=delta_x;
          t3.second+=delta_y;
      }
  };
  
  //now I would like to make in my main program a vector of smart pointers 
  //which I would use do dyn. alloc. "n" Triangles. After that I want to use 
  //std::transform to Translate every single one (with lambda function)
  //I am currently stuck at implementation of this lambda function as you can 
  // see:
  //-------------(main)------------------------------
  int main()
  {
      std::cout&lt;&lt;"How many triangles: ";
      std::cin&gt;&gt;n;
      std::vector&lt;double&gt; translation_vector(2);
      double angle, scale_faktor;
      Point dot1, dot2, dot3; 
      std::vector&lt;std::shared_ptr&lt;Triangle&gt;&gt; vect_smrt_ptr(n);
      for(int i(0); i&lt;n; i++){
          std::cout&lt;&lt;"Input data for the"&lt;&lt;i+1&lt;&lt;". triangle (x1 y1 x2 y2 x3 y3):";
          std::cin&gt;&gt;dot1.first&gt;&gt;dot1.second&gt;&gt;dot2.first&gt;&gt;dot2.second&gt;&gt;dot3.first&gt;&gt;dot3.second;
          std::shared_ptr&lt;Triangle&gt; smrt_ptr(new Triangle(dot1, dot2, dot3));
          vect_smrt_ptr.at(i)=smrt_ptr;
      }
      std::cout&lt;&lt;"Input translation vector (dx dy): ";
      std::cin&gt;&gt;translation_vector.at(0)&gt;&gt;translation_vector.at(1);
  
      //now the tricky part!
      std::transform(&amp;vect_smrt_ptr.at(0), &amp;vect_smrt_ptr.at(vect_smrt_ptr.size()), &amp;vect_smrt_ptr.at(0),
          [translation_vector](Triangle tr){ tr.Translate(translation_vector.at(0), translation_vector.at(1)); }
      );
  </code></pre>