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<World> ptr(x);</div>
<div><span class="Apple-tab-span" style="white-space:pre">        </span>msg = ptr->msg;</div><div>}</div><div><br></div><div>and </div><div><br></div><div><div>World(SEXPREC* &w2) {</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>msg = ((World*)w2)->msg;</div>
<div>}</div></div><div><br></div>With the SEXPREC* & definition, I get a runtime segfault:</div><div><div>> a <- new(World,"sdf")</div><div>> b <- new(World,"bbb")</div><div>> a$greet( )</div>
<div>[1] "sdf"</div><div>> b$greet( )</div><div>[1] "bbb"</div><div>> a$addMsg( b)</div><div><br></div><div> *** caught segfault ***</div><div>address 0x0, cause 'unknown'</div><div><br></div>
<div>Traceback:</div><div> 1: .External(list(name = "CppMethod__invoke_void", address = <pointer: 0x7f838b4034b0>, dll = list(name = "Rcpp", path = "/opt/local/lib/R/library/Rcpp/libs/x86_64/Rcpp.so", dynamicLookup = TRUE, handle = <pointer: 0x7f838b60f330>, info = <pointer: 0x10ee1ec18>), numParameters = -1L), <pointer: 0x7f838b4e6f30>, <pointer: 0x7f838b4f7350>, .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 'memory not mapped'</div>
<div><br></div><div>Traceback:</div><div> 1: .External(list(name = "CppMethod__invoke_void", address = <pointer: 0x7fccb0c370a0>, dll = list(name = "Rcpp", path = "/opt/local/lib/R/library/Rcpp/libs/x86_64/Rcpp.so", dynamicLookup = TRUE, handle = <pointer: 0x7fccb0e09680>, info = <pointer: 0x10dcc3bc0>), numParameters = -1L), <pointer: 0x7fccb0cee700>, <pointer: 0x7fccb0ca5880>, .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"><<a href="mailto:darren@dcook.org">darren@dcook.org</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">> void addMsg(World& w2) {<br>
> msg = msg + w2.msg;<br>
> }<br>
<br>
</div>BTW, this could be (and should be)<br>
void addMsg(const World& w2) { ...}<br>
<div class="im"><br>
> error: no matching function for call to ‘World::World(SEXPREC*&)’<br>
<br>
</div>How about something like:<br>
<br>
World(SEXPREC* &w2){<br>
msg= ((World*)w2)->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>