相关疑难解决方法(0)

创建std :: shared_ptr对象并将其返回到R端(Rcpp)

我正在尝试使用Rcpp为C++脚本编写R绑定.其中一个功能需要a std::shared_ptr object.我发现很难初始化std::shared_ptrobj并将其作为Rcpp::XPtr对象返回到R端.

我试过(最小的例子):

#include <iostream>
#include <memory>
#include <Rcpp.h> 
using namespace Rcpp;
using std::cout;


class TestClass {
  public:
    int value;

    TestClass(int initial_val) {
      value = initial_val;
    };

};


//[[Rcpp::export]]
SEXP get_test_obj() {
  Rcpp::XPtr<std::shared_ptr<TestClass>> ptr(std::make_shared<TestClass>(5), true);
  return ptr;
};
Run Code Online (Sandbox Code Playgroud)

但是得到以下错误:

 no matching function for call to 'Rcpp::XPtr<std::shared_ptr<TestClass> >::XPtr(std::shared_ptr<TestClass>, bool)'
Run Code Online (Sandbox Code Playgroud)

关于如何做到这一点的任何想法?或者我错了吗?

c++ r rcpp

2
推荐指数
2
解决办法
1084
查看次数

标签 统计

c++ ×1

r ×1

rcpp ×1