C++ 错误:重载函数的多个实例“;FindCircumReference“;匹配参数列表
我不知道该怎么办?我得到的错误与标题中的一样:C++ 错误:重载函数的多个实例“;FindCircumReference“;匹配参数列表,c++,C++,我不知道该怎么办?我得到的错误与标题中的一样:error:重载函数“findCircumference”的多个实例与参数列表匹配。 我正在为此任务使用作用域和函数。如果我能找出这个错误,我可以继续在其他项目上工作。请帮忙 #include <iostream> #include <iomanip> using namespace std; // This program will demonstrate the scope rules. // PLACE YOUR
error:重载函数“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
}
#包括
#包括
使用名称空间std;
//本课程将演示范围规则。
//把你的名字写在这里
常数双PI=3.14;
常数倍率=0.25;
void findArea(浮动,浮动);
无效FindCircumReference(浮点,浮点);
int main()
{
cout您的前向声明是针对一个按值接受两个float
参数的函数
void findCircumference(float, float);
但是您的函数签名略有不同,将一个float
by value和第二个作为参考
void findCircumference(float, float&);
// ^
您需要将它们更改为匹配,可能是通过更正转发声明。如果您阅读了函数定义上方的注释,则说明函数必须修改参数
// data out: answer (which alters the corresponding actual parameter)
您可以通过引用传递参数来完成此操作,即追加&
字符
您还需要更改findArea
函数的声明和定义
祝你好运谢谢你的快速回复!这修复了出现的任何错误,但当我运行程序时,它会立即关闭。以下是输出的最终注释:程序“[7736]Project6_5.exe:Native”已退出,代码为0(0x0)。你的代码为我运行(根据我的回答进行了更正)。请注意,findArea
的第二个参数可能也是float&
(代码当前显示一个未初始化的值作为答案)但是我看不到任何明显会崩溃的东西。@user3063562您的main
返回0,因此使用代码0退出意味着您的程序运行完成。如果您从命令行而不是在ide中运行exe,您将看到它的输出(好的和坏的)。或者您可以在结尾添加字符串s;cin>>s;
,强制它在完成之前等待用户输入。它打开ommand提示符,但立即关闭,我也修复了findArea的问题。谢谢您的建议也帮助了第二个问题,只需将字符串更改为浮动,也谢谢您的广告安德鲁·道格拉斯vice,你们真快!