title: Capture class method in a lambda
body: <p>I have several methods in my class. I want a lambda in one method to call another method of the class. But I don't want to capture <code>this</code> so that I can limit the scope of what the lambda has access to. Is this possible? </p>
  
  <p>I've tried to capture the method as <code>[&amp;method = Class::my_method]</code> or variations of that but there's something I'm missing.</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  class Hello
  {
  public:
  
    double test_lambda(const double in)
    {
        // If I capture `this` instead, then this works fine
        const auto a_lambda = [add_number = this-&gt;add_number](const double in)
        {
          return add_number(in);  
        };
        return a_lambda(in);
    }
  
  private:
  
    double add_number(const double in)
    {
        return in + 2.0;
    }
  
  };
  
  int main()
  {
      Hello h;
      std::cout &lt;&lt; "Hello World: " &lt;&lt; h.test_lambda(4.0); // Expect 6
      return 0;
  }
  
  </code></pre>
  
  <p>I would hope that I could capture a method like this but I'm not sure if it's possible.</p>
  
  <p>The reason I want to do this based on a coding preference to limit what the lambda has access to.  For example, if I wanted the lambda to mutate members of a class, I could do</p>
  
  <pre><code>another_lambda = [this](){
  m_value_one = 1.0;
  m_value_two = 2.0;
  // This has access to other members
  }
  </code></pre>
  
  <p>Or to limit what the lambda can mutate, I can do:</p>
  
  <pre><code>another_lambda = [&amp;value_one = this-&gt;m_value_one, &amp;value_two = this-&gt;m_value_two](){
  value_one = 1.0;
  value_two = 2.0;
  // This does not have access to other members
  }
  </code></pre>
  
  <p>The post is asking whether the same can be done with class methods, but it seems that it cannot.</p>