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

Error: More than one instance of overload function "findCircumference" matches the argument list

本文关键字:findCircumference 参数 列表 实例 重载 函数 错误      更新时间:2023-10-16

我不知道该怎么办?我得到的错误就像标题中一样: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
}

正向声明用于按值接受两个float参数的函数

void findCircumference(float, float);

但是您的函数签名略有不同,按值取一个float,第二个作为参考

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

您需要更改它们以匹配,大概是通过更正正向声明。

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

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

您可以通过引用传递一个参数来实现这一点,即附加一个&字符。

您还需要更改findArea函数的声明和定义

祝好运

相关文章:
  • 没有找到相关文章