2011-05-11 377 views
0

我想编译但我不断收到此错误,有没有人看到我的错误在哪里?C++链接错误ld返回1退出状态

C:\用户\ BRIAN '〜1个\应用程序数据\本地\ TEMP \ cc2Feaaa.o(的.text + 0x368)在函数'主':

[连接子错误]未定义参考`正割(双,双,双,双,双,双,双,双,双&,整数&,双)

C:\用户\ BRIAN'〜1 \应用程序数据\本地\ TEMP \ cc2Feaaa.o(+的.text 0x368)ld返回1退出状态

using namespace std; 
#include<iostream> 
#include<cmath> 
#include<iomanip> 
#include<fstream> 
// Declaration of functions used 
void writetable (double, double, double, double); 
void secant(double, double, double, double, double, double, double, double, double&, int&, double); 
void writedata (double, double, double); 
double fx(double, double, double, double, double, double, double); 

const double tol=0.0001; // Tolerance for convergence 
const int max_iter=50;  // Maximum iterations allowed 
// main program 
int main() 
{ 
    int iteration;   // Number of iterations 

    double kr, uc, q, b, radians; 

    double x0, x1;   // Starting values for x 
    double root;   // Root found by secant method 
const double PI = 4.0*atan(1.0); 
ifstream datain ("shuttle.txt"); 
ofstream dataout ("results.txt"); 
datain >> kr >> uc >> q >> b; 
x0= 1000; 
x1 = 200; 
for (double velocity = 16000; velocity <= 17500; velocity += 500) 
{ 
     for (double angle = 10; angle <= 70; angle += 15) 
     { 
        radians= angle * PI/180 ; 
        cout << velocity << endl; 
        cout << radians << endl; 
        cout << angle << endl; 
        secant (radians, velocity, kr, uc, q, b, x0, x1, root, iteration, angle); 

     } 

} 
    writetable(kr, uc, q, b); 

system("pause"); 
} 

// Definition of function "secant" 
// Receives a, b, c, d and x0 values from main program 
// Returns root and the iterations required 
void secant(double radians, double velocity, double kr, double uc, double q, double b, double x0, double x1, double angle, double& root, int& iteration) 
{ 
    double xnminus1, xnplus1, xn; // Local variables 
    iteration=0;     // Initialize iterations 
    xnminus1=x0; 
    xn=x1; 
    do 
    { 
     ++iteration; 
     xnplus1 = xn - fx(radians, velocity, kr, uc, q, b, xn)*(xn-xnminus1)/ 
            (fx(radians, velocity, kr, uc, q, b, xn)-fx(radians, velocity, kr, uc, q, b, xnminus1)); 
     cout<<"x"<<iteration+1<<" = "<<xnplus1<<endl; 
     xnminus1 = xn; 
     xn=xnplus1; 
    } 
    while ((fabs(fx(radians, velocity, kr, uc, q, b, xnplus1)) >= tol)&& (iteration < max_iter)); 
    root=xnplus1; 

    cout<<"\nThe root is = "<<root<<endl; 
    cout<<"The number of iterations was = "<<iteration<<endl; 
    cout<<"The value of f(x) at the root = "<<fx(radians, velocity, kr, uc, q, b, root)<<endl<<endl; 

    if(root <1000) cout << "safe"<<endl<<endl; else cout <<"unsafe"<<endl<<endl; 
    writedata(angle, velocity, root); 
} 
// Defines "fx" 
double fx(double radians,double velocity, double kr, double uc, double q, double b, double ts) 
{ 
    return kr * pow(ts,4.0) + uc * ts - q - pow((velocity/b), 2.0) * sin(radians); 


} 
void writetable(double kr, double uc, double q, double b) 
{ 
    cout <<endl << "Input Parameters:" <<endl; 
    cout<< "Kr(1/K^2)=" << kr << endl << "uc(1/K)=" << uc <<endl << "q(unitless)=" << q << endl << "b(mph)=" << b<< endl; //not done this part yet 
    cout << " angle..............velocity...........surface temp..............safe.........."; 
    cout << " degs...............mph................Kelvin.....................?............"; 
    cout << "--------------------------------------------------------------------------------";  

} 
void writedata (double angle, double velocity, double root) 
{ 
    } 
+0

提供完整的错误信息。 – 2011-05-11 08:11:49

+0

这就是为什么我们没有可观的长和难以阅读的函数参数列表。 – 2016-05-13 13:58:27

回答

5

函数的声明secant

void secant(double, double, double, double, double, double, double, double, double&, int&, double); 

不同于实际执行的签名:

void secant(double radians, double velocity, double kr, double uc, double q, double b, double x0, double x1, double angle, double& root, int& iteration) 
{ 
    ... 
} 

链接器试图寻找与声明的参数列表执行,但没有找到它。

2

您所提供的secant()实施包含错误的参数(9 double的,一个参考doubleint参考,而不是8个double S,A double引用和参考int)。

1

您声明割线为:

void secant(double, double, double, double, double, double, double, double, double&, int&, double); 

,但你把它定义为:

void secant(double , double , double , double , double , double , double , double , double , double& , int&) 
1

割线的定义和声明似乎是不同的...... 在声明中,您有最后一个参数传递由-copy(double),定义其参照(int &)。请看看

相关问题