错误:多个重载函数实例“findCircumference”与参数列表匹配

时间:2013-12-03 22:50:28

标签: c++

我无法弄清楚该怎么办?我在标题中得到了错误:Error: More than one instance of overload function "findCircumference" matches the argument list.

我正在使用范围和函数进行此分配。如果我能弄清楚这个错误,我可以继续处理其他项目。请帮忙。

#include <iostream>
#include <iomanip>
using namespace std;


// This program will demonstrate the scope rules.

// PLACE YOUR NAME HERE


const double PI = 3.14;
const double RATE = 0.25;

void findArea(float, float);
void findCircumference(float, float);


int main()

{

    cout << fixed << showpoint << setprecision(2);
    float radius = 12;

    cout <<" Main function outer block" << endl;
    cout <<" LIST THE IDENTIFIERS THAT are active here" << endl << endl;
    {
        float area;
        cout << "Main function first inner block" << endl;  
        cout << "LIST THE IDENTIFIERS THAT are active here" << endl << endl;

        findArea(radius, area);// Fill in the code to call findArea here

        cout << "The radius = " << radius << endl;
        cout << "The area = " << area << endl << endl;
    }

    {
        float radius = 10;
        float circumference;

        cout << "Main function second inner block" << endl;
        cout << "LIST THE IDENTIFIERS THAT are active here" << endl << endl;

        findCircumference(radius, circumference);

        cout << "The radius = " << radius << endl;
        cout << "The circumference = " << circumference << endl << endl;

    }

    cout << "Main function after all the calls" << endl;
    cout << "LIST THE IDENTIFIERS THAT are active here" << endl << endl;

    return 0;
}

//  *********************************************************************
//                           findArea
//   
//   task:     This function finds the area of a circle given its radius
//   data in:  radius of a circle
//   data out: answer (which alters the corresponding actual parameter)
//
//   ********************************************************************


void findArea(float rad, float answer)
{

    cout << "AREA FUNCTION" << endl << endl;
    cout << "LIST THE IDENTIFIERS THAT are active here"<< endl << endl;
    answer = (rad*PI)*(rad*PI);
    cout << answer <<endl;
    // FILL in the code, given that parameter rad contains the radius, that
    // will find the areato be stored in answer

}

//  ******************************************************************************
//                           findCircumference
//   
//   task:     This function finds the circumference of a circle given its radius
//   data in:  radius of a circle
//   data out: distance (which alters the corresponding actual parameter)
//
//   *****************************************************************************



void findCircumference(float length, float& distance)

{
    cout << "CIRCUMFERENCE FUNCTION" << endl << endl;
    cout << "LIST THE IDENTIFIERS THAT are active here" << endl << endl; 
    distance = (length*2)*PI;
        cout << distance << endl;

    // FILL in the code, given that parameter length contains the radius, 
    // that will find the circumference to be stored in distance

}

2 个答案:

答案 0 :(得分:2)

您的前向声明适用于按值

获取两个float个参数的函数
void findCircumference(float, float);

但是你的功能签名略有不同,一个float按值,第二个作为参考

void findCircumference(float, float&);
//                                 ^

你需要改变它们以匹配,大概是通过纠正前方声明。

答案 1 :(得分:0)

如果您阅读了函数定义上面的注释,它会声明函数必须修改参数。

//   data out: answer (which alters the corresponding actual parameter)

您可以通过引用传递参数,即附加&字符来完成此操作。

您还需要更改findArea函数

的声明和定义 祝你好运