错误C2065:"i":未声明的标识符 [英] error C2065: 'i' : undeclared identifier

查看:145
本文介绍了错误C2065:"i":未声明的标识符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

1> d:\ services \ winservice \ service.cpp(408):错误C2065:``i'':未声明的标识符
1> d:\ services \ winservice \ service.cpp(408):错误C2065:"i":未声明的标识符
1> d:\ services \ winservice \ service.cpp(408):错误C2065:"i":未声明的标识符
1> d:\ services \ winservice \ service.cpp(410):错误C2065:"i":未声明的标识符

1>d:\services\winservice\service.cpp(408) : error C2065: ''i'' : undeclared identifier
1>d:\services\winservice\service.cpp(408) : error C2065: ''i'' : undeclared identifier
1>d:\services\winservice\service.cpp(408) : error C2065: ''i'' : undeclared identifier
1>d:\services\winservice\service.cpp(410) : error C2065: ''i'' : undeclared identifier

else if(nIndex==127)
{
    for(int i = MAX_NUM_OF_PROCESS-1; i >= 0; i--)
    {
        EndProcess(i);
    }
    for(i = 0; i < MAX_NUM_OF_PROCESS; i++)    // Line 408
    {
        StartProcess(i);                          // Line 410
    }



任何人都可以帮助
我是阿拉斯加Xbase ++程序员
电子邮件-xxx@xxx.com [电子邮件已删除]
谢谢



Please can anyone HELP
I am a Alaska Xbase++ Programmer
email - xxx@xxx.com [Email removed]
Thanks

推荐答案

默认情况下,它与某些较早版本的C ++兼容,但默认情况下不再令人满意.我猜这可以通过某些选项来更改,但最好是更改代码本身.
This was compatible by default for some earlier versions of C++, but is no more good by default. I guess this can be changed by some option, but better is to change the code itself.


您好,以以下代码为例:
Hi, taking the following code for example:
for (int i= 0; i < 10; i++)
{
    int nValue= i;
}
for (i = 0; i < 6; i++)
{
    int nValue2= i;
}


此代码适用于Visual C ++ 6.0.但是在更高版本的Visual C ++中,编译器已增强了循环范围.因此,此代码无法由Visual Studio 2005编译.有两种方法可以解决此问题.首先,我建议您按照Solution1,Solution2或Solution3方法将代码更改为:


This code works well for visual C++ 6.0. But in the later version of visual C++, the compiler has emhanced for loop scope. So, this code can''t compile by visual studio 2005. There are two ways to solve this problem. First, which I recommand, you may follow the Solution1,Solution2 or Solution3 method to change the code to :

for (int i= 0; i < 10; i++)
{
    int nValue= i;
}
for (int i = 0; i < 6; i++)
{
    int nValue2= i;
}



第二种方法是更改​​Visual Studio项目设置.请找到以下项目:属性页面"->配置属性"->"C/C ++"->语言"->"For Fore Scope for For Scope",然后将其默认值是"更改为不".之后,尝试构建原始代码.祝您好运.



The second way is changing the visual studio project setting. Please find this item: "property pages"->"Configuration propertites"->"C/C++"->"Language"->"Force Conformance In For Loop Scope" then change its default value "Yes" to "No". After that try to build the original code. Good luck to you.


您在第一个循环中声明的变量i在第一个循环结束时超出范围.这意味着不再声明它,并且您将无法继续使用该变量.您可以在第二个循环中重新声明i,这是我通常要做的.由于这两个循环是不相关的,并且要强调您实际上是在使用其他变量,因此我在下面的代码的第二个循环中声明了第二个变量j.

The variable i that you declared in the first loop goes out of scope at the end of the first loop. That means that it is no longer declared and you can’t continue to use that same variable. You can re-declare i in the second loop, which is what I usually do. Since the two loops are unrelated and to emphasize that you are, in fact, using a different variable I have declared a second variable j in the second loop in the code below.

for(int i = MAX_NUM_OF_PROCESS-1; i >= 0; i--)
    {
        EndProcess(i);
    }
    for(int j = 0; j < MAX_NUM_OF_PROCESS; j++)
    {
        StartProcess(j);
    }


这篇关于错误C2065:"i":未声明的标识符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆