r - 使用 Rcpp 模块通过派生对象公开继承的方法
问题描述
我使用此答案中描述的方法创建了一个几乎为空的 Rcpp 项目。的内容rcpp_hello_world.cpp
已替换为:
#include <Rcpp.h>
using namespace Rcpp;
class A {
public:
virtual int foo() {
return 1;
}
};
class B : public A {
public:
int bar() {
return 2;
}
};
// [[Rcpp::export]]
int fun() {
B b;
return b.foo();
}
RCPP_MODULE(mod_ab) {
class_<A>("A").
constructor().
method("foo", &A::foo);
class_<B>("B")
.constructor()
//.method("foo", &B::foo)
.method("bar", &B::bar);
}
B
public 派生自A
,因此应该可以像在 function 中那样从A
through调用方法。如何通过 公开此方法?如果我取消注释该行B
fun()
RCPP_MODULES
//.method("foo", &B::foo)
我收到以下错误:
rcpp_hello_world.cpp: In function ‘void _rcpp_module_mod_ab_init()’:
rcpp_hello_world.cpp:31:27: error: no matching function for call to ‘Rcpp::class_<B>::method(const char [4], int (A::*)())’
.method("foo", &B::foo)
是否有可能做到这一点,或者我应该创建一个B
转发到其基类的方法并公开它?
解决方案
推荐阅读
- python - 用于服务 Flask 应用程序的等效 Docker CMD
- javascript - 如何在 arcgis javascript api 4.14 中添加网格化参考图形小部件
- windows - 无法根据 InstalledOn 过滤 get-wmiobject
- python - Tkinter 菜单栏
- javascript - 当我折叠、添加或删除面板时,React-hook-form 字段值会丢失
- oracle - 如何仅使用“REPLACE”、“INSTR”或“SUBSTR”oracle函数删除单词之间的空格并用单个下划线替换
- spring-cloud - Spring @RefreshScope - 有条件地重新加载/刷新 bean
- c# - 通过 System.Drawing 将位图缩放为 EMF,特定宽度为毫米?
- node-modules - “../../node_modules/.bin/”的简写?
- java - Java中并行流的实用用例是什么?