[Rcpp-devel] module with a template class

Robin Girard robin.girard at mines-paristech.fr
Sun Apr 7 10:56:01 CEST 2013

I 'm sure this is not a path toward a workaround, but comes as a comment to my understanding of what RCPP_EXPOSED_CLASS does : the weird thing is that when I declare a dummy function that instanciates my template class e.g. : 

void dummyfct(){
  dynamicOf_<firstClass> toto;

and "comment" the line //RCPP_EXPOSED_CLASS(dynamicOf_<firstClass>)

then the whole thing installs properly and 

when I do :
I got : 
constructing firstClass
C++ object <0x7fba60c7d270> of class 'dynamicOf_firstClass' <0x7fba61890ab0>

which seems fine ? why do I construct "constructing firstClass" here ? of class 'dynamicOf_firstClass'? 
I'll dig further into that but if someone can explain me what's happening ... 

----- Mail original -----
De: "Robin Girard" <robin.girard at mines-paristech.fr>
À: rcpp-devel at lists.r-forge.r-project.org
Envoyé: Samedi 6 Avril 2013 23:05:06
Objet: [Rcpp-devel] module with a template class

Hi again list, 

I'm continuing to investigate the possibilities of modules for my project. 
and I can't found how to push a template class instance into the module. Since I'm not very good it my be a bad programming habbit of mine (in this case this is not a Rcpp question I admit) or it can be that what I'm trying to do is not allowed

below is a dumb example with class  definition module definition and error log which ends up with 
"invalid use of incomplete type ‘class dynamicOf_<firstClass>"

any comments or idea  

------ templateModule.h
#include <RcppCommon.h>

class firstClass ;
class secondClass ;
template<class aClass>
class dynamicOf_;

class firstClass
    double value_ ;
    ~firstClass(){Rcpp::Rcout<<"destructing firstClass"<<std::endl;};
    firstClass(){Rcpp::Rcout<<"constructing firstClass"<<std::endl;};
    firstClass(double value) : value_(value){};

class secondClass 
    ~secondClass(){Rcpp::Rcout<<"destructing secondClass"<<std::endl;};
    secondClass(){Rcpp::Rcout<<"constructing secondClass"<<std::endl;};
template<class aClass>
class dynamicOf_{
  public :
    aClass obj;
    double dyn_info;

---- templatemodule.cpp

#include "TemplateModule.h"
#include <Rcpp.h>


  using namespace Rcpp;
  class_<firstClass>( "firstClass" )
    class_<secondClass>( "secondClass" )
    class_<dynamicOf_<firstClass> >( "dynamicOf_firstClass" )

------ error log 
/Library/Frameworks/R.framework/Versions/2.15/Resources/library/Rcpp/include/Rcpp/XPtr.h: In function ‘void Rcpp::standard_delete_finalizer(T*) [with T = dynamicOf_<firstClass>]’:
/Library/Frameworks/R.framework/Versions/2.15/Resources/library/Rcpp/include/Rcpp/module/class.h:39:   instantiated from ‘Rcpp::class_<dynamicOf_<firstClass> >’
TemplateModule.cpp:21:   instantiated from here
/Library/Frameworks/R.framework/Versions/2.15/Resources/library/Rcpp/include/Rcpp/XPtr.h:39: warning: possible problem detected in invocation of delete operator:
/Library/Frameworks/R.framework/Versions/2.15/Resources/library/Rcpp/include/Rcpp/XPtr.h:38: warning: ‘obj’ has incomplete type
TemplateModule.h:26: warning: declaration of ‘class dynamicOf_<firstClass>’
/Library/Frameworks/R.framework/Versions/2.15/Resources/library/Rcpp/include/Rcpp/XPtr.h:39: note: neither the destructor nor the class-specific operator delete will be called, even if they are declared when the class is defined.
/Library/Frameworks/R.framework/Versions/2.15/Resources/library/Rcpp/include/Rcpp/module/class.h: In constructor ‘Rcpp::class_<Class>::class_(const char*, const char*) [with Class = dynamicOf_<firstClass>]’:
TemplateModule.cpp:21:   instantiated from here
/Library/Frameworks/R.framework/Versions/2.15/Resources/library/Rcpp/include/Rcpp/module/class.h:71: error: invalid use of incomplete type ‘class dynamicOf_<firstClass>’
TemplateModule.h:26: error: declaration of ‘class dynamicOf_<firstClass>’
/Library/Frameworks/R.framework/Versions/2.15/Resources/library/Rcpp/include/Rcpp/module/Module_generated_Constructor.h: In member function ‘Class* Rcpp::Constructor_0<Class>::get_new(SEXPREC**, int) [with Class = dynamicOf_<firstClass>]’:
TemplateModule.cpp:24:   instantiated from here
/Library/Frameworks/R.framework/Versions/2.15/Resources/library/Rcpp/include/Rcpp/module/Module_generated_Constructor.h:37: error: invalid use of incomplete type ‘class dynamicOf_<firstClass>’
TemplateModule.h:26: error: declaration of ‘class dynamicOf_<firstClass>’
make: *** [TemplateModule.o] Error 1
ERROR: compilation failed for package ‘ReproducibleExample’

Dr. Girard Robin
Chargé de Recherche

MINES-ParisTech / Département Energétique et Procédés / PERSEE / Groupe ERSEI
Centre Procédés, Energies Renouvelables et Systèmes Energétiques (PERSEE)
Center for Processes, Renewables Energies and Energy Systems
Renewable Energies & Smartgrids (ERSEI)

1 Rue Claude Daunesse - CS 10207 - F-06904 Sophia Antipolis Cedex
Tel: + (~99), Fax: +
e-mail : robin.girard at mines-paristech.fr

web page perso http://www.mines-paristech.fr/Services/Annuaire/&?id=8828
statoverflow : http://stats.stackexchange.com/users/223/robin-girard
web page centre PERSEE : http://www.cep.mines-paristech.fr/
linkedin : http://www.linkedin.com/profile/view?id=14907272&trk=tab_pro

Le lien vaut mieux que le bien.

CONFIDENTIALITY : This  e-mail  and  any attachments are
confidential and may be privileged. If  you are not a
named recipient, please notify the sender immediately and
do not disclose the contents to another person, use it for
any purpose or store or copy the information in any medium.

CONFIDENTIALITE : Ce message et les éventuelles pièces
attachées sontconfidentiels et peuvent être une
communication protégée. Si vous n'êtes pas dans la liste
des destinataires, veuillez informer l'expéditeur
immédiatement et ne pas ouvrir ni divulguer le contenu
à une tierce personne, ne pas l'utiliser pour quelque
raison que ce soit, ne pas stocker ou copier l'information
qu'il contient sur un quelconque support.

Rcpp-devel mailing list
Rcpp-devel at lists.r-forge.r-project.org

More information about the Rcpp-devel mailing list