title: Why won't this lambda capture this variable with a deleted constructor by reference?
body: <p>My compiler, Visual Studio 19, says &quot;Attempting to reference a deleted function&quot;:</p>
  <pre><code>class AClass 
  {public:
      AClass(const AClass&amp; other) = delete;
      AClass() {}
      AClass(AClass&amp;&amp; other) { }
      AClass&amp; operator=(const AClass&amp; other) = delete;
      AClass&amp; operator=(AClass&amp;&amp; other) { return *this; }
      int member;
  };
  
  
  void main()
  {
      AClass a;
      AClass&amp; aRef = a;
  
      [=]() { return aRef.member; }; // &quot;Attempting to reference a deleted function&quot;
  
  }
  </code></pre>
  <p>I assume it's trying to call the copy constructor, which is deleted, but I don't understand why as I'm trying to capture by reference by [=] value, meaning I don't copy the object AClass, I don't see how any copy is involved. My understanding is that the lambda looks something like this:</p>
  <pre><code>struct lambda {
      AClass&amp; refToAClass; // &lt;--- this is the captured object
      lambda(AClass&amp; captureVariable) : refToAClass(captureVariable) {}
      int operator()() const
      {
          return refToAClass.member;
      }
  };
  
  
  void main()
  {
        // AND I CAN CONSTRUCT THE LAMBDA, NO COPYING OF AClass INVOLVED
        AClass a;
        AClass&amp; aRef = a;
  
        lambda lam(aRef); // WORKS FINE
  }
  </code></pre>
  <p>How is a copy involved in this case? And how do I capture that reference?</p>