<html><head></head><body bgcolor="#FFFFFF"><div>Iirc, this is not implemented yet. </div><div><br></div><div>There is a chance we might add this feature in the future. </div><div><br></div><div>Cheers, </div><div><br></div><div>Romain<br><br><div><br></div></div><div><br>Le 21 déc. 2011 à 10:59, Yasir Suhail <<a href="mailto:yusuhail@gmail.com">yusuhail@gmail.com</a>> a écrit :<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> World() : msg("hello"){}</div>
<div> void set(std::string msg) { this->msg = msg; }</div><div> std::string greet() { return msg; }</div><div> void addMsg(World& w2) {</div><div><span class="Apple-tab-span" style="white-space:pre">        </span>msg = msg + w2.msg;</div>
<div> }</div><div>private:</div><div> 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&’ 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> from /usr/local/lib/R/site-library/Rcpp/include/Rcpp.h:27,</div><div> from rcpp_module.cpp:1:</div>
<div>/usr/local/lib/R/site-library/Rcpp/include/Rcpp/traits/Exporter.h: In constructor ‘Rcpp::traits::Exporter<T>::Exporter(SEXPREC*) [with T = World, SEXPREC* = SEXPREC*]’:</div><div>/usr/local/lib/R/site-library/Rcpp/include/Rcpp/as.h:51:51: 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: 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: instantiated from ‘SEXPREC* Rcpp::CppMethod1<Class, void, U0>::operator()(Class*, SEXPREC**) [with Class = World, U0 = World&, SEXPREC* = SEXPREC*]’</div>
<div>rcpp_module.cpp:86:1: 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*&)’</div><div>rcpp_module.cpp:30:5: note: candidates are: World::World()</div>
<div>rcpp_module.cpp:28:13: note: World::World(const World&)</div><div>make: *** [rcpp_module.o] Error 1</div></div><div><br></div><div>Looking at <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>