C++ 代码错误和警告:解决 a.cpp 中的编译问题
{"title":"a.cpp: In function ‘List ReadInput(List&)’: \na.cpp:11:14: warning: unused variable ‘temp’ [-Wunused-variable]\n int num,i,temp;\n ^~~~\na.cpp:16:1: warning: no return statement in function returning non-void [-Wreturn-type]\n }\n ^\na.cpp: In function ‘int main()’: \na.cpp:27:9: warning: unused variable ‘i’ [-Wunused-variable]\n int i;\n ^\na.cpp: In function ‘List Delete(List&, ElementType, ElementType)’: \na.cpp:38:29: error: base operand of ‘->’ has non-pointer type ‘List {aka LNode}’\n for(i = 0, j = 0; i <= L->last; i++)\n ^~\na.cpp:40:13: error: base operand of ‘->’ has non-pointer type ‘List {aka LNode}’\n if(L->Data[i] >= minD && L->Data[i] <= maxD)\n ^~\na.cpp:40:35: error: base operand of ‘->’ has non-pointer type ‘List {aka LNode}’\n if(L->Data[i] >= minD && L->Data[i] <= maxD)\n ^~\na.cpp:42:14: error: base operand of ‘->’ has non-pointer type ‘List {aka LNode}’\n L->Data[j] = L->Data[i];\n ^~\na.cpp:42:27: error: base operand of ‘->’ has non-pointer type ‘List {aka LNode}’\n L->Data[j] = L->Data[i];\n ^~\na.cpp:46:6: error: base operand of ‘->’ has non-pointer type ‘List {aka LNode}’\n L->last = j - 1;\n ^~\na.cpp: In function ‘List ReadInput(List&)’: \na.cpp:12:9: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]\n scanf("%d",&num);\n ~~~~~^~~~~~~~~~~\na.cpp:14:11: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]\n scanf("%d",&L.Data[i]);\n ~~~~~^~~~~~~~~~~~~~~~~\na.cpp: In function ‘int main()’: \na.cpp:29:10: warning: ignoring return value of ‘int scanf(const char*, ...)’, declared with attribute warn_unused_result [-Wunused-result]\n scanf("%d %d", &minD, &maxD);\n ~~~~~^~~~~~~~~~~~~~~~~~~~~~~\n什么意思,怎么改正内容:这是一个C++代码的警告和错误信息。\n\n警告信息:\n1. unused variable ‘temp’:表示变量‘temp’未被使用。\n2. no return statement in function returning non-void:表示在非void类型的函数中缺少返回语句。\n3. unused variable ‘i’:表示变量‘i’未被使用。\n4. ignoring return value of ‘int scanf(const char*, ...)’:表示忽略了scanf函数的返回值。\n\n错误信息:\n1. base operand of ‘->’ has non-pointer type ‘List’:表示‘->’运算符的基本操作数是非指针类型‘List’。\n2. base operand of ‘->’ has non-pointer type ‘List’:表示‘->’运算符的基本操作数是非指针类型‘List’。\n3. base operand of ‘->’ has non-pointer type ‘List’:表示‘->’运算符的基本操作数是非指针类型‘List’。\n4. base operand of ‘->’ has non-pointer type ‘List’:表示‘->’运算符的基本操作数是非指针类型‘List’。\n5. base operand of ‘->’ has non-pointer type ‘List’:表示‘->’运算符的基本操作数是非指针类型‘List’。\n6. base operand of ‘->’ has non-pointer type ‘List’:表示‘->’运算符的基本操作数是非指针类型‘List’。\n7. ignoring return value of ‘int scanf(const char*, ...)’:表示忽略了scanf函数的返回值。\n\n要解决这些问题,可以进行以下更改:\n1. 删除未使用的变量‘temp’,或者在需要使用它的地方使用它。\n2. 在函数‘ReadInput’中添加返回语句,确保返回一个值。\n3. 删除未使用的变量‘i’。\n4. 检查‘Delete’函数中的指针操作,确保正确使用指针。\n5. 检查‘Delete’函数中的指针操作,确保正确使用指针。\n6. 检查‘Delete’函数中的指针操作,确保正确使用指针。\n7. 检查‘Delete’函数中的指针操作,确保正确使用指针。\n8. 检查‘Delete’函数中的指针操作,确保正确使用指针。\n9. 检查‘Delete’函数中的指针操作,确保正确使用指针。\n10. 检查‘ReadInput’函数中的scanf函数的返回值,确保正确使用。\n11. 检查‘ReadInput’函数中的scanf函数的返回值,确保正确使用。\n12. 检查‘main’函数中的scanf函数的返回值,确保正确使用。
原文地址: http://www.cveoy.top/t/topic/pb4C 著作权归作者所有。请勿转载和采集!