c++ - 我怎么能在我的 C 代码中包含这个 C++ 函数
问题描述
我有以下 C 函数,它是用 C 编写的代码的一部分。
void pusher(int part, int ntime,long double x[3], long double v[3], long double E[3], long double B[3], long double Vth, long double c2, long double x_new[3], long double v_new[3]){
long double x_mid[3];
long double upart_new[3];
// half time-step for Euler step
long double dth = 0.5*dt;
// position x_{i+1/2} at time t_{i+1/2} + dt/2 (1st-order Euler scheme)
for(int i=0;i<3;i++){
x_mid[i] = x[i] + v[i]*dth;
}
// TO DO: Get E, B at new position
/* I want to add the Cpp function at this point in the code. */
// interpolate_fields();
// 'Kick' particle (update velocity) based on the chosen integrator
switch(pusher_name) {
case 1 :
Vay(v, E, B, c2, upart_new);
break;
case 0 :
Boris_relativ(v, E, B, c2, upart_new);
break;
}
long double gL_new = gamma_u(upart_new, c2);
// full position update at t_{i+1} = t_{i+1/2} + dt/2 = t_i + dt
for(int i=0;i<3;i++){
v_new[i] = upart_new[i]/gL_new;
x_new[i] = x_mid[i] + v_new[i]*dth;
}
}
我还有以下 Cpp 函数,我想在代码中的指定点包含它。为避免在问题中包含 Cpp 代码,我已在此处上传文件:
https://www.dropbox.com/s/vbsxme9vozci4tz/ba_interp3.cpp?dl=0
这可能吗?
关于我如何做到这一点的任何建议?
解决方案
推荐阅读
- php - 如何将单选按钮选择解析到数据库
- bash - 如何将一组文件名作为命令的参数传递?
- jquery - 当今天的日期通过 var 时添加类
- orm - 感觉硬生生:在 gorm 中使用连接
- java - 垃圾收集器可以清除我的部分数据吗?
- c# - 如何从 web api 返回 byte[] 并在客户端读取它
- python-3.x - 如何在 Python Discord Bot 中停止多个倒计时?
- inno-setup - ArchitecturesAllowed Inno Setup 指令是否涉及 CPU 架构或操作系统架构?
- lua - lua 代码文件中的函数 rembuff:floor() 出错:尝试调用方法“floor”(一个 nil 值)
- javascript - AJAX 请求无法在代码隐藏文件中找到 WebMethod