【问题标题】:error: Too few argument to function错误:函数的参数太少
【发布时间】:2013-10-14 22:42:31
【问题描述】:

我知道有很多类似的问题,但我太新了。所以我的问题是我必须做一个makefile并编译我的项目,但在某些时候它会返回错误。

Main.cpp

#include <iostream>
#include <stdlib.h>
#include "SquareRootCalculation.h"
using namespace std;
int main(int argc, char* argv[])
{
    int number = atoi(argv[0]);
    int th = atoi(argv[1]);
    float result = SquareRoot(number, th);
return 0;
}

InitialGuess.cpp

#include <iostream>
#include <math.h>
using namespace std;
int InitialGuess(int number)
{
   float numberLength = 0;
for(; number != 0; number /= 10, numberLength++);
float n = nearbyint(sqrt(numberLength));
float y = numberLength * pow(10, n);
return  0;
}

SqrtCalc.cpp

#include <iostream>
#include "InitialGuess.h"
#include <math.h>
using namespace std;
int SquareRoot(int number, int th, float y)
{
int initialGuess = InitialGuess(y);
float x = initialGuess;
 for (int k=1; k< th; ++k)
    {
        x = (x + (number / x ))/2; 
    }
cout<<x;    
 return 0;
}

我也有 InitialGuess.h

int InitialGuess(int number, float y);

和 sqrtcalc.h

int SquareRoot(int number, int th);

还有一个makefile

all:
g++ Main.cpp InitialGuess.cpp SquareRootCalculation.cpp -o FR    

返回错误

InitialGuess.h 1 In function 'int SquareRoot (int,int,float)'
InitialGuess.h "too few arguments 'int InitialGuess(int, float)'

此时 SqrtCalc 7 出错

【问题讨论】:

    标签: c++ compilation


    【解决方案1】:

    这是你的函数的声明:

    int SquareRoot(int number, int th, float y)
    

    你就是这样称呼它的:

    SquareRoot(number, th);
    

    您缺少第三个参数。

    此外,InitialGuess 接受两个参数,但你有一个。

    【讨论】:

      【解决方案2】:

      错误是不言自明的:

      在 .h 文件中您定义了 int InitialGuess(int number, float y); - 带有 2 个参数,但在 .cpp 文件中 int InitialGuess(int number) - 带有一个

      SquareRoot 函数存在同样的问题

      【讨论】:

        猜你喜欢
        • 2010-12-16
        • 2018-04-22
        • 1970-01-01
        • 1970-01-01
        • 2018-03-26
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多