[Rcpp-devel] Module with out default constructor.
Dirk Eddelbuettel
edd at debian.org
Wed Oct 27 21:54:53 CEST 2010
On 27 October 2010 at 13:32, Andrew Redd wrote:
| Is it possible with Rcpp Modules to have a class that does not have a
| default constructor? Consider this example
| -----
| #include <R.h>
| #include <Rcpp.h>
| class c1{
| private:
| int n;
| int * x;
| c1();
| public:
| c1(int n):n(n){}
| int getn(){return n;}
| };
| RCPP_MODULE(c1){
| using namespace Rcpp;
| class_<c1>("c1")
| .property("n",&c1::getn)
| ;
| }
Looks like Notepad++ doesn't like indenting, eh? ;)
| -----
| Here I have a class that I do not want to allow to initialize without
| specifying n. Yes it does not do anything but the question is related to a
| class where constructors and destructors allocate and free special memory.
| And Yes I know that this fails on compile since c1() is private. Can Rcpp
| handle this kind of setup?
Unsure.
| If not suggestions about workarounds?
I would start with something defensive along the lines of
-- default constructor, in it mark variable as NA (aka uninitialized)
-- variable gets a setter and a getter
-- use the setter directly or in another init() routine
-- complain in the getter() if called on uninitalized var
This should work with the existing framework, so I'd try that.
Cheers, Dirk
--
Dirk Eddelbuettel | edd at debian.org | http://dirk.eddelbuettel.com
More information about the Rcpp-devel
mailing list