Thanks Darren, Douglas, Richard, and Dirk!<div><br></div><div>I can compile with the following definitions:</div><div><br></div><div><div>World(SEXP x) {</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>Rcpp::XPtr&lt;World&gt; ptr(x);</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>msg = ptr-&gt;msg;</div><div>}</div><div><br></div><div>and </div><div><br></div><div><div>World(SEXPREC* &amp;w2) {</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>msg = ((World*)w2)-&gt;msg;</div>
<div>}</div></div><div><br></div>With the SEXPREC* &amp; definition, I get a runtime segfault:</div><div><div>&gt; a &lt;- new(World,&quot;sdf&quot;)</div><div>&gt; b &lt;- new(World,&quot;bbb&quot;)</div><div>&gt; a$greet( )</div>
<div>[1] &quot;sdf&quot;</div><div>&gt; b$greet( )</div><div>[1] &quot;bbb&quot;</div><div>&gt; a$addMsg( b)</div><div><br></div><div> *** caught segfault ***</div><div>address 0x0, cause &#39;unknown&#39;</div><div><br></div>
<div>Traceback:</div><div> 1: .External(list(name = &quot;CppMethod__invoke_void&quot;, address = &lt;pointer: 0x7f838b4034b0&gt;,     dll = list(name = &quot;Rcpp&quot;, path = &quot;/opt/local/lib/R/library/Rcpp/libs/x86_64/Rcpp.so&quot;,         dynamicLookup = TRUE, handle = &lt;pointer: 0x7f838b60f330&gt;,         info = &lt;pointer: 0x10ee1ec18&gt;), numParameters = -1L),     &lt;pointer: 0x7f838b4e6f30&gt;, &lt;pointer: 0x7f838b4f7350&gt;, .pointer,     ...)</div>
<div> 2: a$addMsg(b)</div></div><div><br></div><div><br></div><div>With the SEXP and Rcpp::XPtr definition, it also caused segfault:</div><div><div> *** caught segfault ***</div><div>address 0xfffffa, cause &#39;memory not mapped&#39;</div>
<div><br></div><div>Traceback:</div><div> 1: .External(list(name = &quot;CppMethod__invoke_void&quot;, address = &lt;pointer: 0x7fccb0c370a0&gt;,     dll = list(name = &quot;Rcpp&quot;, path = &quot;/opt/local/lib/R/library/Rcpp/libs/x86_64/Rcpp.so&quot;,         dynamicLookup = TRUE, handle = &lt;pointer: 0x7fccb0e09680&gt;,         info = &lt;pointer: 0x10dcc3bc0&gt;), numParameters = -1L),     &lt;pointer: 0x7fccb0cee700&gt;, &lt;pointer: 0x7fccb0ca5880&gt;, .pointer,     ...)</div>
<div> 2: b$addMsg(a)</div></div><div><br></div><div>Perhaps there is some problem with the pointer conservation?</div><div><br></div><div><br></div><div><div class="gmail_quote">On Wed, Dec 21, 2011 at 5:56 PM, Darren Cook <span dir="ltr">&lt;<a href="mailto:darren@dcook.org">darren@dcook.org</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">&gt;     void addMsg(World&amp; w2) {<br>
&gt; msg = msg + w2.msg;<br>
&gt;     }<br>
<br>
</div>BTW, this could be (and should be)<br>
  void addMsg(const World&amp; w2) { ...}<br>
<div class="im"><br>
&gt; error: no matching function for call to ‘World::World(SEXPREC*&amp;)’<br>
<br>
</div>How about something like:<br>
<br>
  World(SEXPREC* &amp;w2){<br>
    msg= ((World*)w2)-&gt;msg;<br>
  }<br>
<span class="HOEnZb"><font color="#888888"><br>
Darren<br>
<br>
--<br>
Darren Cook, Software Researcher/Developer<br>
<br>
<a href="http://dcook.org/work/" target="_blank">http://dcook.org/work/</a> (About me and my work)<br>
<a href="http://dcook.org/blogs.html" target="_blank">http://dcook.org/blogs.html</a> (My blogs and articles)<br>
</font></span><div class="HOEnZb"><div class="h5">_______________________________________________<br>
Rcpp-devel mailing list<br>
<a href="mailto:Rcpp-devel@lists.r-forge.r-project.org">Rcpp-devel@lists.r-forge.r-project.org</a><br>
<a href="https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel" target="_blank">https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel</a></div></div></blockquote></div><br></div>