[Rcpp-devel] error while calling function in loop

Sean Robert McGuffee sean.mcguffee at gmail.com
Mon Mar 28 20:30:11 CEST 2011


RInside R(argc, argv); //this would appear to be a class called RInside
definining a variable called R initialized with argc and argv variables.

To declare it globally, you would need to define it inside a *.cpp file
once, and only once. Usually this is easiest to do at the top of a *.cpp
file that uses it. Then do the same thing in other files that use it, but in
those cases, place the term "extern" in front of the declaration.

Example:

RInside R; //this is a declaration
extern RInside R; //this is a line for another file that lets the compiler
know it is declared in another *.cpp file.

Then inside your main function where you must be to get the argc and argv
variables, you could then initialize the class:
R=RInside(argc,argv);

I haven't ever used this class, and my instructions assume that a default
constructor for RInside is accessible to you. If it were not, then you would
have to make a pointer to it in the global scope and then assign it by
reference:

//outside of all {}'s at the top of a *.cpp file:
RInside *Rptr; //this is a pointer of type RInside declaration
extern RInside *Rptr; //this is a line for another file that lets the
compiler know Rptr is declared in another *.cpp file

//inside main
RInside R(argc, argv);
Rptr=&R;

I hope this helps,

Sean 



On 3/26/11 10:18 AM, "Dirk Eddelbuettel" <edd at debian.org> wrote:

> 
> On 26 March 2011 at 19:06, nandan amar wrote:
> | Ohh Then i sud select reply to all
> | 
> | Thanks Dirk,
> | But RInside R(argc, argv) is not a variable .
> 
> If R is not a variable here, what is it?
> 
> | How can I declare it globally or share its instance.
> | If it is not related to R/Rcpp please leave some related pointer.
> 
> Sorry, but you simply need to read some more about C++ and or
> programming. Google for 'good c++ book'. There is a free one I like at
> 
>    http://www.icce.rug.nl/documents/cplusplus/
> 
> which is also included in Debian and Ubuntu as a package.
> 
> Dirk




More information about the Rcpp-devel mailing list