SELECT TOP(1) WITH TIES Name, Weight
FROM (
SELECT 'A', 100 UNION ALL
SELECT 'B', 150 UNION ALL
SELECT 'C', 25 UNION ALL
SELECT 'D', 150 UNION ALL
SELECT 'E', 110
)[Product] (Name, Weight)
ORDER BY Weight DESC
当我编译这段代码时,它在第23行给出了一个错误,告诉我变量“gender”(我在函数“printResults”中作为参数放置)是一个未声明的标识符,即使我清楚地声明它之前有11行(第12行)。为什么会这样?
答案 0 :(得分:2)
改变这个:
if (y == 1)
int gender = askGender();
对此:
int gender;
if (y == 1)
gender = askGender();
甚至更好:
int gender = 0; // default: 0
if (y == 1)
gender = askGender();