用c ++替换旧的c

时间:2016-01-17 17:57:15

标签: c++ c replace

以下是简单的旧C代码:

typedef struct {
    double EditionDate;
    double epoch;
    char ModelName[32];
    double *Main_Field_Coeff_G;
    double *Main_Field_Coeff_H;
    double *Secular_Var_Coeff_G;
    double *Secular_Var_Coeff_H;
    int nMax;
    int nMaxSecVar;
    int SecularVariationUsed;
    double CoefficientFileEndDate; 

} MAGtype_MagneticModel;

MAGtype_MagneticModel *TimedMagneticModel, *MagneticModels[1];

if(!MAG_robustReadMagModels(filename, &MagneticModels, epochs)) {
        printf("\n WMM.COF not found.  Press enter to exit... \n ");
    fgets(ans, 20, stdin);
    return 1;
}

这是c ++中的错误:

    131 IntelliSense: argument of type "MAGtype_MagneticModel *(*)[1]" is
incompatible with parameter of type "MAGtype_MagneticModel *(*)[]"

error C2664: 'int MAG_robustReadMagModels(char *,MAGtype_MagneticModel
*(*)[],int)' : cannot convert argument 2 from 'MAGtype_MagneticModel *(*)[1]' 
to 'MAGtype_MagneticModel *(*)[]'

如何在c#中修复此错误?

1 个答案:

答案 0 :(得分:1)

我没有得到你用C ++编译的C代码,但是想在C#中解决它的错误,为什么?吴。无论如何功能声明是 - > int MAG_robustReadMagModels(char *, MAGtype_MagneticModel *(*)[] ,int)和第二个参数是:

MAGtype_MagneticModel *(*)[] - >您可以声明绑定的数组,即MAGtype_MagneticModel *(*)[1],因为在一维数组的情况下必须填充数组绑定。

将第二个参数的声明更改为 - > MAGtype_MagneticModel **只需将函数调用为MAG_robustReadMagModels(filename, MagneticModels, epochs)

即可