我正在尝试使用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语句中完成这项工作?
最佳答案
在if语句之后,WeightLimits超出范围。为避免这种情况,请在if之前声明它:
wb_Parameters *WeightLimits;
if (strcmp(CurrentAircraft->PhenomType,"100") == 0)
WeightLimits = set100Parameters();
else
WeightLimits = set300Parameters();