通过 IF 语句选择结构
我试图使用 IF 语句选择两个可能的 ANSI C 表达式之一。每个表达式本身都可以正常工作,例如...
wb_Parameters *WeightLimits = set100Parameters();
但是当通过 IF 选择它们时,例如...
if (strcmp(CurrentAircraft->PhenomType,"100") == 0)
wb_Parameters *WeightLimits = set100Parameters();
else
wb_Parameters *WeightLimits = set300Parameters();
我收到错误消息“使用未声明的标识符‘WeightLimits’。”我需要做什么才能在 IF 语句中实现此功能?
I am trying to select one of two possible ANSI C expressions using an IF statement. Each expression works fine by itself, eg...
wb_Parameters *WeightLimits = set100Parameters();
but when they're selected via an IF eg...
if (strcmp(CurrentAircraft->PhenomType,"100") == 0)
wb_Parameters *WeightLimits = set100Parameters();
else
wb_Parameters *WeightLimits = set300Parameters();
I get the error message "Use of undeclared identifier 'WeightLimits'." What do I need to do to make this work inside an IF statement?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
WeightLimits 在 if 语句之后超出范围。为了避免这种情况,请在 if 之前声明它:
WeightLimits goes out of scope after the if statement. To avoid that, declare it before the if:
首先声明,然后分配正确的值:
如果不先声明它就会超出范围并且不能再使用。
First declare and then assign the right value:
If you don't first declare it it goes out of scope and it can not be used anymore.