错误C2065:'我' :未声明的标识符

时间:2017-10-11 11:14:51

标签: c++ visual-studio-2013

有人可以解释为什么我的代码不正确吗?它给出了错误:

  

错误C2065:'我' :未声明的标识符

QVariant

2 个答案:

答案 0 :(得分:2)

你试图在我的范围之外进行访问。变量在循环范围中声明,最后一个if语句在此范围之外。您可以在循环之前声明它或重写代码,以便最后一个if语句在循环中。

答案 1 :(得分:0)

正如@Murzinio所示,const int iEN11 = 4; // motor1 enable on phase 1 const int iEN12 = 4; // motor1 enable on phase 2 const int iEN13 = 4; // motor1 enable on phase 3 const int iIN11 = 3; // motor1 phase 1 signal const int iIN12 = 5; // motor1 phase 2 signal const int iIN13 = 6; // motor1 phase 3 signal const int iEN21 = 7; // motor2 enable on phase 1 const int iEN22 = 7; // motor2 enable on phase 2 const int iEN23 = 7; // motor2 enable on phase 3 const int iIN21 = 9; // motor2 phase 1 signal const int iIN22 = 10; // motor2 phase 2 signal const int iIN23 = 11; // motor2 phase 3 signal 变量在for循环的范围内,而if语句不在同一范围内。

下面,我展示了一个稍微改进的版本,其中包含对更改原因的评论:

i

此代码与您的代码的正确版本具有相同的效果,并具有删除不必要的临时变量的额外好处。

我确实建议在c ++上阅读更多内容。如果您无法访问任何文献,我总是发现http://www.cplusplus.com/doc/tutorial/非常有帮助。

相关问题