我正在使用递归完成家庭作业,我的 productfz
函数将拒绝与我合作。 Visual Studio 告诉我,当我在 main 中调用它时,我需要在“第一个”变量周围加上括号。我只在我的主要参数中的每个变量之前添加了“无符号”,因为它摆脱了错误消息。但是,该函数甚至不会执行。我不会在我的运行代码中收到“tester”消息。
我在这里做错了什么?
#include <iostream>
using namespace std;
unsigned productfz();
unsigned productfz(unsigned a, unsigned b)
{
//nothing for now
cout << "this is a tester" << endl;
return a;
}
int main()
{
unsigned int first = 7;
unsigned b = 4;
unsigned productfz(unsigned first, unsigned b);
return 0;
}
最佳答案
在您的 main()
中,您没有正确调用 productfz 行:
unsigned productfz(unsigned first, unsigned b);
是函数声明而不是函数调用。
如果你想调用这个函数,只需写:
productfz(first,b);
关于c++ - 为什么这个使用未签名产品的简单功能不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22124157/