gpt4 book ai didi

c++ - 错误 : More than one instance of overload function "findCircumference" matches the argument list

转载 作者:行者123 更新时间:2023-11-28 03:02:39 26 4
gpt4 key购买 nike

我不知道该怎么办?我得到了与标题中一样的错误:错误:重载函数“findCircumference”的多个实例与参数列表匹配。

我正在为这项任务使用范围和功能。如果我能弄清楚这个错误,我就可以继续从事其他项目。请帮忙。

#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&);
// ^

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

关于c++ - 错误 : More than one instance of overload function "findCircumference" matches the argument list,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20363328/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com