views:

101

answers:

3

How to use RCPP_MODULE(yada) in C++. My C++ program gives error if I use

const char* hello( std::string who ){
std::string result( "hello " ) ;
result += who ;
return result.c_str() ;
}

RCPP_MODULE(yada)
{
using namespace std;
function( "hello", &hello ) ;
};

Error are:
1. Error 1 error C2065: 'yada' : undeclared identifier
2. Error 2 error C2448: 'RCPP_MODULE' : function-style initializer appears to be a function definition

Can anyone help me in fixing these error?

+1  A: 

RCPP? I'm guessing you mean this: http://dirk.eddelbuettel.com/code/rcpp.html

I have no experience of it, but I'd guess you are missing a #include line somewhere. Maybe

#include "rccp.h"

??

Roddy
There is no Rcpp.h library.
+1  A: 

The point of RCPP_MODULE is to expose C++ to R.

You need to include R.h and Rdefines.h and state using namespace Rcpp;

0A0D
There is no r.h and Rdefines.h library.
When I include R.h, Rdefines.H and using namespace Rcpp I get error. For using namespace error is : Error: unexpected symbol in " using namespace"
+2  A: 

Rcpp does not work with Visual Studio, see Question 2.7 in Rcpp FAQ.

Dirk Eddelbuettel