标头声明错误C ++

时间:2014-06-12 14:26:01

标签: c++

我对标题声明有误解。请帮忙m:

我的cpp文件:distanceMatrixFunc.cpp

float  DistanceMatrix::distanceMatrixFunc(int particleNumber,float xPos [], float yPos      
[], float zPos []) 
{
    int j, k  = 0;
    distanceMatrix_x[] = new float*[particleNumber];
    distanceMatrix_y = new float*[particleNumber];
    distanceMatrix_z = new float*[particleNumber];
    distanceMatrix   = new float*[particleNumber];

    for (int i = 0; i < particleNumber; i++){
    distanceMatrix_x[i] = new float[particleNumber];
    distanceMatrix_y[i] = new float[particleNumber];
    distanceMatrix_z[i] = new float[particleNumber];
    distanceMatrix[i] = new float[particleNumber];
}

distanceMatrixFunc.h函数:

class DistanceMatrix {
    float distanceMatrix_x;
    float distanceMatrix_y;
    float distanceMatrix_z;
    float distanceMatrix;
    int particleNumber;
    float xPos ;
    float yPos ;
    float zPos;
    float distanceMatrixFunc( int  particleNumber, float xPos , float  yPos , floatzPos);
};         

问题出在我的cpp文件中:     float DistanceMatrix :: distanceMatrixFunc(int particleNumber,float xPos [],float yPos     [],浮动zPos []) 错误声明与float distanceMatrix

不兼容

1 个答案:

答案 0 :(得分:2)

您在头文件中的声明需要三个float个变量,您在.cpp文件中的定义需要三个float个数组。更改头文件中的声明以期望三个数组:

float distanceMatrixFunc( int  particleNumber, float xPos[] , float  yPos[] , floatzPos[]);

或.cpp文件中的定义需要三个float s:

float distanceMatrixFunc( int  particleNumber, float xPos , float  yPos , float zPos) {
    ...
}