title: Javascript style closure in C++
body: <p>First off, apologies as this title probably made some of you c++ guys throw up in your mouth a little bit. However, let me explain what I'm trying to accomplish.</p>
  
  <p>I'm passing a lambda (call it funcA) as a parameter to another function (call it funcB). Is there a way for me to declare variables within funcB and access them within the scope of funcA without passing them to funcA as parameters, similar to how javascript closures work?</p>
  
  <p>A simple example (which fails obviously) would be as follows:</p>
  
  <pre><code>void funcB(std::function&lt;void()&gt; funcA) {
      int testInt = 44;
      funcA();
  }
  
  int main() {
      funcB([&amp;]() {
          std::cout &lt;&lt; testInt; // undefined identifier
      });
  
      return 0;
  }
  </code></pre>