title: Rcpp: Calling function with object as argument
body: <p>I have a function in Rcpp, which creates a very long map-structure within a class. I've given a simple example of it below:</p>
  
  <pre><code>#include &lt;Rcpp.h&gt;
  using namespace Rcpp;
  
  class A{
  private:
    std::map&lt;int, int&gt; m_map;
  public:
    void fill_map(const size_t limit){
      for(size_t i=0; i&lt;limit; ++i){
        m_map[i] = i;
      }
    }
    size_t size_map(){return m_map.size();}
  };
  
  // [[Rcpp::export]]
  void func1(const size_t limit) {
    A a;
    a.fill_map(limit);
  }
  
  /* NOT WORKING */
  // [[Rcpp::export]]
  void func2(A a)
  {
    std::cout &lt;&lt; a.size_map() &lt;&lt; "\n";
  }
  /* NOT WORKING */
  </code></pre>
  
  <p>Say I call <code>func1(1e7)</code>, which fills up the map in the <code>a</code>-object. I need to pass this <code>A</code>-object to other functions as shown above with <code>func2</code>. </p>
  
  <p>However, my example with <code>func2</code> doesn't work. Within the <code>Rcpp</code>-framework, what is the correct and most efficient approach to call <code>func2</code> with an object defined in a previous function?</p>