<html><head></head><body bgcolor="#FFFFFF"><div>Iirc, this is not implemented yet.&nbsp;</div><div><br></div><div>There is a chance we might add this feature in the future.&nbsp;</div><div><br></div><div>Cheers,&nbsp;</div><div><br></div><div>Romain<br><br><div><br></div></div><div><br>Le 21 déc. 2011 à 10:59, Yasir Suhail &lt;<a href="mailto:yusuhail@gmail.com">yusuhail@gmail.com</a>&gt; a écrit&nbsp;:<br><br></div><div></div><blockquote type="cite"><div>I need to pass a class as an argument in a function I am exposing to R. From the skeleton package module, let us say that I have<div><br></div><div><div>class World {</div><div>public:</div><div>&nbsp; &nbsp; World() : msg("hello"){}</div>
<div>&nbsp; &nbsp; void set(std::string msg) { this-&gt;msg = msg; }</div><div>&nbsp; &nbsp; std::string greet() { return msg; }</div><div>&nbsp; &nbsp; void addMsg(World&amp; w2) {</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>msg = msg + w2.msg;</div>
<div>&nbsp; &nbsp; }</div><div>private:</div><div>&nbsp; &nbsp; std::string msg;</div><div>};</div><div><br></div></div><div>However, this gives errors of the sort</div><div><div>/usr/local/lib/R/site-library/Rcpp/include/Rcpp/module/Module_generated_CppMethod.h:186:4: error: invalid initialization of non-const reference of type ‘World&amp;’ from an rvalue of type ‘World’</div>
<div>In file included from /usr/local/lib/R/site-library/Rcpp/include/RcppCommon.h:306:0,</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;from /usr/local/lib/R/site-library/Rcpp/include/Rcpp.h:27,</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;from rcpp_module.cpp:1:</div>
<div>/usr/local/lib/R/site-library/Rcpp/include/Rcpp/traits/Exporter.h: In constructor ‘Rcpp::traits::Exporter&lt;T&gt;::Exporter(SEXPREC*) [with T = World, SEXPREC* = SEXPREC*]’:</div><div>/usr/local/lib/R/site-library/Rcpp/include/Rcpp/as.h:51:51: &nbsp; instantiated from ‘T Rcpp::internal::as(SEXPREC*, Rcpp::traits::r_type_generic_tag) [with T = World, SEXPREC* = SEXPREC*]’</div>
<div>/usr/local/lib/R/site-library/Rcpp/include/Rcpp/as.h:75:89: &nbsp; instantiated from ‘T Rcpp::as(SEXPREC*) [with T = World, SEXPREC* = SEXPREC*]’</div><div>/usr/local/lib/R/site-library/Rcpp/include/Rcpp/module/Module_generated_CppMethod.h:186:4: &nbsp; instantiated from ‘SEXPREC* Rcpp::CppMethod1&lt;Class, void, U0&gt;::operator()(Class*, SEXPREC**) [with Class = World, U0 = World&amp;, SEXPREC* = SEXPREC*]’</div>
<div>rcpp_module.cpp:86:1: &nbsp; instantiated from here</div><div>/usr/local/lib/R/site-library/Rcpp/include/Rcpp/traits/Exporter.h:31:37: error: no matching function for call to ‘World::World(SEXPREC*&amp;)’</div><div>rcpp_module.cpp:30:5: note: candidates are: World::World()</div>
<div>rcpp_module.cpp:28:13: note: &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; World::World(const World&amp;)</div><div>make: *** [rcpp_module.o] Error 1</div></div><div><br></div><div>Looking at&nbsp;<a href="http://dirk.eddelbuettel.com/code/rcpp/Rcpp-extending.pdf">http://dirk.eddelbuettel.com/code/rcpp/Rcpp-extending.pdf</a>, it seems that I can extend Rcpp::as to account for my classes, but I still have two questions:</div>
<div>1. How do I define the constructor World(SEXP)? Is there a working example somewhere for a user defined C++ class?</div><div>2. Can I also use pointers and pass-by-reference as these are more often used in real C++ code.</div>
<div><br></div><div>In short, I'd appreciate a way to pass my C++ classes (as the class and also by ref. or pointer) that have been exposed to R as arguments to exposed functions. How do I achieve that?</div><div><br>
</div><div>Thanks!</div>
</div></blockquote><blockquote type="cite"><div><span>_______________________________________________</span><br><span>Rcpp-devel mailing list</span><br><span><a href="mailto:Rcpp-devel@lists.r-forge.r-project.org">Rcpp-devel@lists.r-forge.r-project.org</a></span><br><span><a href="https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel">https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel</a></span></div></blockquote></body></html>