首先这是我在stackoverflow上的第一个问题。我正在努力完成一项家庭作业,但我不知道我可能会做错什么。C++奇怪的错误,“没有从'int'转换为'int(__cdecl *)(float,float)'”
当我尝试第二次运行某个函数时,出现错误“无法从'int'转换为'int(__cdecl *)(float,float)''”。该函数应该返回0,-1或+1,并在if/else语句中使用。
这里的代码,我指的是块...
#include <iostream>
using namespace std;
////this function returns a -1 if the left pan has a weight more than the right, a 0 if the weights of the two pans are equal, and a +1 if the right pan has a greater weight than the left
int weigh(float leftpan, float rightpan)
{
//compare the pan weights, return value
}
float findOddRock(float r1, float r2, float r3, float r4, float r5, float r6, float r7)
{
//first weigh
float first_leftpan = r1 + r2;
float first_rightpan = r3 + r4;
weigh(first_leftpan, first_rightpan);
if(weigh == 0){
cout << "this program is working so far";
float second_leftpan = r5; //this brings up an error for some reason
float second_rightpan = r6;
weigh(second_leftpan, second_rightpan);
//here's where I get the error, no conversion from 'int' to 'int (__cdecl *)(float,float)'
if(weigh == 0){ //be careful here, changed from second_weigh to weigh
float third_leftpan = r5;
float third_rightpan = r7;
weigh(third_leftpan, third_rightpan);
}
//
int main()
{
//find the light rock
findOddRock(2.0, 2.0, 2.0, 2.0, 2.0, 2.0, 1.0);
}
我接受了建议,现在程序运行了,但findOddRock不返回任何我包含的字符串。阻止它返回任何字符串的函数有什么问题? – Charli