函数不接受 1 个参数
function does not take 1 arguments
我不知道我的代码出了什么问题。我创建了两个函数,一个显示问候消息,另一个函数完成简单的计算。
#include "stdafx.h"
#include <iostream>
#include <Windows.h>
using namespace std;
void greetings();
int total();
int main()
{
void greetings();
int num1, num2, sum;
cout<<"Enter a number to calculate : ";
cin>>num1;
cout<<"Enter another number to add : ";
cin>>num2;
sum = num1 + num2;
cout<<"The total number is "<<total(sum)<<endl;
system("PAUSE");
return 0;
}
/*Every function is down here*/
void greetings(){
cout<<"Welcome to the function 5"<<endl;
cout<<"Here we will try to call many function as possible"<<endl;
}
int total(int a, int b){
return a + b;
}
我收到此错误消息:
函数不接受 1 个参数
cout<<"The total number is "<<total(sum)<<endl;
这是你的问题。Total 需要 2 个参数,但在上行中您只传递一个参数。
您需要这样做:
sum = total(num1, num2);
cout<<"The total number is "<<sum<<endl;
和
int total(int, int);
相关文章:
- 函数不接受 X 参数,函数使用默认参数
- 为什么不接受具有默认分配参数的函数作为 0-arg 生成器?
- 函数不接受 C++ 参数
- SQLHANDLE-Parameters:函数不接受x个参数(但实际上确实如此)
- 函数不接受 1 个参数
- 为什么析构函数不接受C++中的参数?
- 为什么C++可变参数模板不接受 iostream 值作为参数?
- C++:将引用作为参数传递,但该函数不接受引用作为参数
- 我的构造函数方法不接受参数(DirectX / Windows)
- 可变参数模板化构造函数不接受 x 参数
- 为什么 std::is_invocable 不接受非类型模板参数
- 错误 C2660:'MouseListener::MousePressed':函数不接受 4 个参数
- 不接受静态成员函数作为 constexpr 参数
- 方法指针映射,编译器说他们不接受任何参数
- GCC 不接受默认模板参数中的包扩展
- 为什么Clang和VS2013接受移动大括号初始化的默认参数,而不接受GCC 4.8或4.9
- C++ 中的特征库给出错误 C2660:"特征::矩阵基<Derived>::特征值":函数不接受 2 个参数
- strtrok_s函数不接受2个参数
- 函数不接受一个参数
- 带有 const 参数的方法不接受非 const 参数