64位平台上的编译错误C2664
Compiler error C2664 on 64 bit platform
我有一个在Visual Studio 2012中使用win32平台编译和运行的程序。将平台更改为X64后,它给出以下错误消息:
" test_integral .cpp(27):错误C2664: 'hcubature_v':无法将参数2从'int (__cdecl *)(unsigned int,unsigned int,const double *,void *,unsigned int,double *)'转换为'integrand_v' "
谁能给点建议?谢谢你!
#include <iostream>
#include "cubature.h"
#include <ctime>
#include <limits>
using namespace std;
int f_v(unsigned ndim, unsigned npts, const double *x, void *fdata, unsigned fdim, double *fval) {
double sigma = *((double *) fdata);
unsigned i, j;
for (j = 0; j < npts; ++j) { // evaluate the integrand for npts points
double sum = 0;
for (i = 0; i < ndim; ++i) sum += x[j*ndim+i] * x[j*ndim+i];
fval[j] = exp(-sigma * sum);
};
return 0; // success
}
int main(){
double xmin[3] = {-2,-2,-2}, xmax[3] = {2,2,2}, sigma = 0.5;
double val_v,err_v, time_v;
const clock_t begin_time_v = clock();
for (int j = 0; j<1000;j++)
{
// hcubature_v calculates a multidimensional integration.
hcubature_v(1, f_v, &sigma, 1, xmin, xmax, 0, 0, 1e-4, ERROR_INDIVIDUAL, &val_v, &err_v);
}
cout << float( clock () - begin_time_v ) / CLOCKS_PER_SEC<<endl;
printf("Computed integral = %0.10g +/- %gn", val_v, err_v);
cin.get();
}
下面是一些附加的定义:
/* a vector integrand of a vector of npt points: x[i*ndim + j] is the
j-th coordinate of the i-th point, and the k-th function evaluation
for the i-th point is returned in fval[i*fdim + k]. Return 0 on success
or nonzero to terminate the integration. */
typedef int (*integrand_v) (unsigned ndim, size_t npt,
const double *x, void *,
unsigned fdim, double *fval);
/* as hcubature, but vectorized integrand */
int hcubature_v(unsigned fdim, integrand_v f, void *fdata,
unsigned dim, const double *xmin, const double *xmax,
size_t maxEval, double reqAbsError, double reqRelError,
error_norm norm,
double *val, double *err);
您应该使用用于定义integrand_v
的确切类型。
代替:
int f_v(unsigned ndim, unsigned npts, const double *x, void *fdata, unsigned fdim, double *fval) {
^^^^^^
使用
int f_v(unsigned ndim, size_t npt, const double *x, void *fdata, unsigned fdim, double *fval) {
^^^^^^
它可以在32位工作,可能是因为size_t
和unsigned
碰巧是相同的类型。
它不能在64位工作,因为它们是不同的类型
相关文章:
- 使用解算器SparseLU并获得错误C2664
- VS 2017 错误 C2664 地图插入尝试
- 使用自定义对象声明shared_ptr数组时出现错误 C2664
- 编译器错误 C2664 使用 std::map 和自定义类作为其值
- 如何在 VC++ 中通过引用传递另一个对象的方法(错误 C2664)
- 在C++中构造模板函数时出现编译错误 C2664 和 C2440
- 了解错误 C2664:无法转换参数 1
- 错误 C2664:无法从'NvPhysicalGpuHandle'转换参数 1
- 错误 C2664 和 E0167 被难倒
- 尝试创建unique_ptr时出现错误 C2664
- 错误 C2664:"errno_t wcstombs_s(size_t *,字符 *,size_t,常量 wchar_t *,size_t)":无法转换参数 4
- 错误C2664:无法转换参数错误
- 在集合中转换为小写 C++ 错误 C2664
- 错误 C2664:无法将参数 1 从 'int' 转换为 'int []'
- 将互斥锁数组传递给函数时出现错误 C2664
- 错误 C2664:"发送":无法将参数 2 从"服务器问候语"转换为"常量字符 *"
- 错误C2664:无法转换参数(指纹传感器检测)
- C++ 错误 1 错误 C2664 传递数组指针
- 错误 C2664:'CComboBox::InsertString':无法将参数 2 从 'const char [4]' 转换为 'LPCTSTR'
- 创建面向对象的链表时出现编译问题(编译器错误C2664)