我在下面的头文件中定义了一个名为Spiketimesolver
的结构:
#include <math.h>
#include "plot_support.h"
struct Spiketimesolver {
const Doub tau_0, I_0, V_start, I_start;
Spiketimesolver(const Doub tau_0, const Doub I_0, const Doub V_start,
const Doub I_start) :
tau_0(tau_0), I_0(I_0), V_start(V_start), I_start(I_start)
{}
Doub operator()(const Doub t) {
const Doub I = get_I(I_start, t, tau_0);
const Doub V = get_V(I_start, t, tau_0, I_0, V_start, I);
return 0.5 * pow((V - 1), 2);
}
};
(get_I
和get_V
在我的文件plot_support.h
中定义。它们的定义在这里无关紧要。)
在单独的模块中,我将此结构实例化如下:
^{pr2}$在这里,所有的论点都是双重的。在
我想将solver
传递给我定义的函数:
template<class T> PyObject* NRpyObject(T &a) {
// default applies to all function objects or other structs
PyObject *thing = PyCapsule_New((void*)a,NULL,NULL);
return thing;
}
^{void *pointer
作为第一个参数。在
当我试图编译时,对于调用NRpyObject(solver)
,我得到以下错误:
In file included from analysis_cmodule.cpp:2:0:
nr3python.h: In instantiation of ‘PyObject* NRpyObject(T&) [with T = Spiketimesolver; PyObject = _object]’:
analysis_cmodule.cpp:16:27: required from here
nr3python.h:183:52: error: invalid cast from type ‘Spiketimesolver’ to type ‘void*’
PyObject *thing = PyCapsule_New((void*)a,NULL,NULL);
^
我做错了什么?在
^{} 的第一个参数必须是指针。您正试图通过将
^{1}$a
转换为void*
来实现这一点。但是,编译器不喜欢这样。我猜你需要使用:相关问题 更多 >
编程相关推荐