错误 C2664:“print_result”:无法将参数 1 从“int (__cdecl *)(int,int,in
error C2664: 'print_result' : cannot convert parameter 1 from 'int (__cdecl *)(int,int,int)' to 'int'
#include<iostream>
using namespace std;
bool is_different(int x, int y, int z);
int max_of_three(int x, int y, int z);
int greater_of_two(int x, int y);
int min_of_three(int x, int y, int z);
int smaller_of_two(int x, int y);
void print_result(int min_of_three, int max_of_three);
int main ()
{
int x, y, z;
while(1==1)
{
cout << "Please input 3 different integers." << endl;
cin >> x >> y >> z;
if (is_different (x, y, z))
{break;}
}
print_result(min_of_three, max_of_three);//error here
}
bool is_different (int x, int y, int z)
{
if (x!=y && x!=z && y!=z)
{
return true;
}
else
{return false;}
}
int greater_of_two (int x, int y)
{
if (x > y)
return x;
if (y > x)
return y;
return 0;
}
int max_of_three (int x, int y, int z)
{
return greater_of_two(greater_of_two(x, y) , z);
}
int smaller_of_two (int x, int y)
{
if (x < y)
return x;
if (y < x)
return y;
return 0;
}
int min_of_three (int x, int y, int z)
{
return smaller_of_two(smaller_of_two(x, y) , z);
}
void print_result (int min_of_three, int max_of_three)
{
cout << "The minimum value of the three is " << min_of_three << endl;
cout << "The maximum value of the three is " << max_of_three << endl;
}
我正在尝试编写一个程序来查找赋值的三个不同输入整数的最大值和最小值,这是我第一次处理函数,我不明白错误的含义。
您正在尝试传递作为签名的函数指针的min_of_three
和max_of_three
:
int(*)(int, int, int)
print_result
期望int
论点。
你想要这个:
print_result(min_of_three(x,y,z), max_of_three(x,y,z));
函数min_of_three(x,y,z)
并max_of_three(x,y,z)
返回int
,然后用作print_result
函数的参数。
相关文章:
- 无符号长长 int in 循环的奇怪行为
- std::sort in vector<int> 返回 0 而不是值
- const int const&和const int&in C++有什么区别?
- 使用 static int 返回 int&in 函数
- 在函数调用中使用类型vector<pair<int,int>>::iterator&in
- 警告:格式"%d"需要类型为"int*"的参数,但参数5的类型为"in
- 了解C++代码 - "Get the number of digits in an int"
- What does int foo = bar << ' '; mean in c++?
- Parsing int in C++11 - stoi
- 初始化静态 std::map<int, unique_ptr<int>> in C++
- Fibonacci C++-从“int”到“int*”的转换无效,并且初始化了“int fibo(int,int*,in
- 错误 C2664:“print_result”:无法将参数 1 从“int (__cdecl *)(int,int,in
- int arrays in C/C++
- SQLite in 10 UWP App Assertion Error (p->iForeGuard==(int)FOREGUARD);
- v[long long int] in C++
- std::p riority_queue<int, std::vector<int>, std::更大的<int>> in min_heap函数
- *&in void headInsert(DoubleLinkList*&head, int theData)是什么意思。是否等同于 void headInsert(DoubleLinkList he
- C++ map<int, int> in Python
- 标准::make_pair: "cannot convert ‘int*’ to ‘std::pair<EndPointAddr*, EndPointAddr*>*’ in initial
- Char to Int in C++?