c++编译器调用错误
C++ Compiler error with calls
在我的计算机科学课上,我们正在编写一个程序,要求测量4个等腰梯形的高度,底部和顶部,计算周长并确定哪个周长最大。我的程序还没有完成,但是我得到错误,说没有匹配的函数来调用askInput
, calcPerimeter
和findMax
。下面是上下文的代码(抱歉,如果答案是显而易见的,或者我的代码是草率的,这是我第一次上编程课)。
#include <iostream>
#include <string>
using namespace std;
void intro();
void askInput();
double calcPerimeter();
double findMax();
double highest;
int main()
{
intro();
double t1, b1, h1, p1; //Top, bottom, height, and perimiter of first trapezoid
double t2, b2, h2, p2,
t3, b3, h3, p3,
t4, b4, h4, p4; //other four trapezoids
double max; //largest perimeter
askInput(t1, b1, h1, "first");
askInput(t2, b2, h2, "second");
askInput(t3, b3, h3, "third");
askInput(t4, b4, h4, "fourth");
p1 = calcPerimeter(t1, b1, h1);
p2 = calcPerimeter(t2, b2, h2);
p3 = calcPerimeter(t3, b3, h3);
p4 = calcPerimeter(t4, b4, h4);
max = findMax(p1, p2, p3, p4);
cout << "Results" << endl;
cout << "tFirst: tTop:" << t1 << "tBottom: " << b1 << "tHeight: " << h1 << "tPerimeter: " << p1 << endl;
cout << "tSecond: tTop:" << t2 << "tBottom: " << b2 << "tHeight: " << h2 << "tPerimeter: " << p2 << endl;
cout << "tThird: tTop:" << t3 << "tBottom: " << b3 << "tHeight: " << h3 << "tPerimeter: " << p3 << endl;
cout << "tFourth: tTop:" << t4 << "tBottom: " << b4 << "tHeight: " << h4 << "tPerimeter: " << p4 << endl;
cout << endl << "tLargest Perimeter: " << highest << endl;
system("pause");
return 0;
}
void intro()
{
cout << "Lab G: Trapezoid with largest perimeter" << endl;
cout << "---------------------------------------" << endl;
cout << "This program will calculate the perimeter of four trapezoids." << endl;
cout << "You will have to enter the top, bottom, and height of each trapezoid." << endl;
cout << "The program will then find the trapezoid with the largest perimeter and output it." << endl;
}
void askInput(double &top, double &bottom, double &height, string whichT)
{
cout << "Enter values for the " << whichT << " trapezoid." << endl;
cout << "tTop: ";
cin >> top;
cout << "tBottom: ";
cin >> bottom;
cout << "tHeight: ";
cin >> height;
}
double calcPerimeter(double top, double bottom, double height)
{
double answer;
//some calculations
return answer;
}
double findMax(double a, double b, double c, double d)
{
double highest;
highest = a;
if (b > highest)
{
highest = b;
}
if (c > highest)
{
highest = c;
}
if (d > highest)
{
highest = d;
}
return highest;
}
声明中的函数签名必须与实现中的签名匹配。这意味着声明必须包含所有需要的函数形参类型。
void askInput(double &top, double &bottom, double &height, string whichT);
double calcPerimeter(double top, double bottom, double height);
double findMax(double a, double b, double c, double d);
您的函数声明和定义不匹配。像你在定义中所做的那样声明它们,这应该可以工作。
void askInput(); -->
void askInput(double &, double &, double &, string );
double calcPerimeter();-->
double calcPerimeter(double & , double & , double& );
double findMax();-->
double findMax(double &, double &, double &, double &);
这些函数的原型不包括参数。askInput()
是不同于askInput(double &, double&, double&, string)
的函数
我研究c++已经有一段时间了,但我认为我至少看到了两个问题-
- 你需要在顶部声明函数的完整签名。
- 至少对于
askInput
,您正在传递值并取消引用它们。这看起来很奇怪。
希望这对你有帮助!
相关文章:
- C++ 结构错误"调用'erase'没有匹配函数
- 错误:调用 .. at return 语句时没有匹配函数
- 从C++代码抛出错误调用 JavaScript 回调函数 - nbind
- 错误:调用"make_pair"没有匹配函数
- 错误:调用 std::thread 没有匹配函数
- SFML 中的分段错误 调用 sf::窗口::关闭后
- 错误:调用函数指针没有匹配函数
- 汇编错误:调用基本型构造函数时无效的转换
- 错误:调用计数器::计数器()没有匹配函数
- C++ 通过函数指针错误调用成员函数
- 错误:调用 cargaison::cargaison() 时没有匹配函数
- 简单矩阵类,错误:调用私有构造函数
- 带有返回类型的错误调用模板到会员函数
- 错误:调用没有匹配函数(无法解决?
- 从 C 代码链接错误调用C++函数(使用 gcc 进行链接)
- 错误:调用 'pybind11::buffer_info::buffer_info 没有匹配函数
- 错误:调用terminate引发exceptionAbort陷阱:6
- 错误调用功能无法转换类型
- C++ 中的文件处理错误 - 调用"std::basic_fstream<char, std::char_traits<char> >::open(const char[8],
- 对成员函数set_value的错误调用是不明确的(在 xcode 中使用 pugixml 库)