<div dir="ltr">Hi all, <div><br></div><div>I am calling from R (say funcR) a c++ function (say funcCpp) which needs either some programmer-defined c++ class (say programmerClassCpp1, 2, etc...) or a user-defined c++ class (say userClassCpp). Here is an illustration of what I am doing:</div><div><br></div><div>funcR(..., class="ClassCpp"){</div><div>  </div><div>  # do something and then call the c++ function</div><div>   </div><div>   funcCpp(class);<br></div><div>}</div><div><br></div><div>funcCpp(std::string classCpp){</div><div><br></div><div>  switch(classCpp){</div><div>      case "class1" : point to the programmer defined c++ class programmerClassCpp1; break;</div><div>      case "class2" : point to the programmer defined c++ class programmerClassCpp2; break;<br></div><div>      case "new": point to the user defined c++ class userClassCpp; break; </div><div>      default : Rcpp::stop("not supported class");</div><div>     };</div><div>}<br></div><div><br></div><div>This post  </div><div><br></div><div>  <a href="http://gallery.rcpp.org/articles/passing-cpp-function-pointers/">http://gallery.rcpp.org/articles/passing-cpp-function-pointers/</a></div><div><br></div><div>reflects what I need for a function and I am wondering whether it is possible to do this for a class. The obvious solution is to replicate manually what has been done in the post to each method of the class (for instance, work on a vector of functors to the class methods), but I don't see it as the optimal solution.</div><div><br></div><div>Many thanks for any hint,</div><div>Yousra</div></div>