未定义的错误

时间:2013-12-03 01:51:49

标签: c++ undefined-reference

我收到一条错误,指的是对

的未定义引用
 `slope(double*, double*, double*, double*, double*, int, double)', 

但我在程序中定义了斜率。所以我不明白它的说法是未定义的,有人可以解释一下这段代码有什么问题谢谢。

这是我的代码。

#include <fstream>
#include <iostream>
#include <string>
#include <iomanip>
#include <cmath>
#include <stdlib.h>

using namespace std;

void read ();
void slope(double[],double[],double[],double[],double[],int,double);
void write(double[],double[],double[],double[],double[],double);
double temp, R1, R2, R3, R4,rsq;

int main ()
{

    int indx=0;
    read();
    return 0;   
}

void read()
{

    ifstream indata("c:\\doc1\\temperaturedata.txt");
    int indx=0;
    if(indata == NULL)
    {
        cout<< "There is no file go get it from the CD"<< endl;
        return;
    }
    const int columns = 5;
    const int rows = 11;

    double Ihatearray[rows][columns];
    string temparature;
    getline(indata, temparature);
    for(int i = 0; i < rows; ++i)
    {
        for (int j = 0; j < columns; ++j)
            {
                cout << "\t" << flush;
                indata >> Ihatearray[i][j];
                cout.setf(ios::fixed);
                cout << setprecision(2) << Ihatearray[i][j] <<flush;
            }
            cout << endl;

    }
    indata.close();
    slope(&temp, &R1, &R2, &R3, &R4,indx,rsq);
}
void slope(double x[], double y[], double& m, double& b, int n,double r)
{
    int i;
double xsum = 0., ysum = 0., xave, yave, x2sum = 0., y2sum = 0.,xysum =0.;

for(int i = 0; i < n; i++)
{
    xsum  += x[i];
    ysum  += y[i];
    x2sum += x[i] * x[i];
    y2sum += y[i] * y[i];
    xysum += x[i] * y[i];
}

xave=xsum/n;
yave=ysum/n;

m=(xysum-yave*xsum)/(x2sum-xave*xsum);
b=yave-m*xave;
r=(xysum-n*xave*yave)/(sqrt(x2sum-n*xave*xave)*sqrt(y2sum-n*yave*yave));

write (&temp, &R1, &R2, &R3, &R4,rsq);

}
void write (double temp [], double R1[], double R2[], double R3[],double R4[],double
            rsq)
{
    //Where I will print out a table of the results.
}

1 个答案:

答案 0 :(得分:2)

slope(double x[], double y[], double& m, double& b, int n,double r)

不同
slope(double*, double*, double*, double*, double*, int, double)

double&double*不一样