“声明”阴影“参数”是什么意思。
我正在尝试制作一个函数,以返回我将传递给它的整数号码的两倍。我在我的代码中收到以下错误消息:
声明'int x'阴影一个参数int x; “
这是我的代码:
#include <iostream>
int doublenumber();
using namespace std;
int doublenumber(int x)// <-- this is the function which returns double the value .
{
int x;
return 2 * x;
cout << endl;
}
int main()
{
int a;
cout << "Enter the number that you want to double it : " << endl;
cin >> a;
doublenumber(a);
return 0;
}
I am trying to make a function that returns double the integer number that I will pass to it. I am getting the following error message with my code:
declaration of 'int x' shadows a parameter int x; "
Here is my code:
#include <iostream>
int doublenumber();
using namespace std;
int doublenumber(int x)// <-- this is the function which returns double the value .
{
int x;
return 2 * x;
cout << endl;
}
int main()
{
int a;
cout << "Enter the number that you want to double it : " << endl;
cin >> a;
doublenumber(a);
return 0;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您将
X
作为参数,然后尝试将其声明为本地变量,这是关于“阴影”的投诉所指的。You have
x
as a parameter and then try to declare it also as a local variable, which is what the complaint about "shadowing" refers to.我之所以这样做,是因为您的建议非常有帮助,这是最终结果:
I did it because your advice was so helpful, and this is the final result :
您的代码有一些问题。您的声明和功能定义死亡不匹配。因此,删除声明无需它。
您正在声明本地X变量内部函数,该函数将阴影您的函数参数。
There are some problem with your code. Your declaration and definition of function dies not match. So remove declaration as no necessity of it.
You are declaring local x variable inside function which will shadow your function arguments.