error C2275 illegal use of this type as an expression 解决方法

本文介绍了解决VC编译错误C2275的方法,该错误源于C99之前的编译标准限制。文章提供了两种解决方案:一是将文件扩展名改为.cpp;二是确保所有声明位于函数的开始部分。

在VC中编译xxx.c文件出现错误error C2275 illegal use of this type as an expression 

问题在于C99之前要求所有的声明必须放在函数块的起始部分,这也是C和C++的重要区别。

方法: 1). 修改成xxx.cpp 。 2). 把声明放在函数起始部分。

参考:http://stackoverflow.com/questions/9549521/compiler-error-c2275

这个代码用VC++6.0编译出错,显示“-------------------Configuration: 123344 - Win32 Debug-------------------- Compiling... 123.c c:\users\administrator\desktop\新建文件夹\123344\123.c(76) : error C2275: 'HashNode' : illegal use of this type as an expression c:\users\administrator\desktop\新建文件夹\123344\123.c(21) : see declaration of 'HashNode' c:\users\administrator\desktop\新建文件夹\123344\123.c(76) : error C2065: 'new_node' : undeclared identifier c:\users\administrator\desktop\新建文件夹\123344\123.c(77) : error C2223: left of '->record' must point to struct/union c:\users\administrator\desktop\新建文件夹\123344\123.c(78) : error C2223: left of '->next' must point to struct/union c:\users\administrator\desktop\新建文件夹\123344\123.c(82) : error C2275: 'HashNode' : illegal use of this type as an expression c:\users\administrator\desktop\新建文件夹\123344\123.c(21) : see declaration of 'HashNode' c:\users\administrator\desktop\新建文件夹\123344\123.c(82) : error C2065: 'current' : undeclared identifier c:\users\administrator\desktop\新建文件夹\123344\123.c(83) : error C2223: left of '->next' must point to struct/union c:\users\administrator\desktop\新建文件夹\123344\123.c(84) : error C2223: left of '->next' must point to struct/union c:\users\administrator\desktop\新建文件夹\123344\123.c(86) : error C2223: left of '->next' must point to struct/union c:\users\administrator\desktop\新建文件夹\123344\123.c(88) : warning C4047: '=' : 'struct HashNode *' differs in levels of indirection from 'int ' c:\users\administrator\desktop\新建文件夹\123344\123.c(104) : error C2275: 'HashNode' : illegal use of this type as an expression c:\users\administrator\desktop\新建文件夹\123344\123.c(21) : see declaration of 'HashNode' c:\users\administrator\desktop\新建文件夹\123344\123.c(104) : error C2065: 'node' : undeclared identifier c:\users\administrator\desktop\新建文件夹\123344\123.c(106) : warning C4047: '==' : 'int ' differs in levels of indirection from 'void *' c:\users\administrator\desktop\新建文件夹\123344\123.c(110) : error C2143: syntax error : missing ';' before 'type' c:\users\administrator\desktop\新建文件夹\123344\123.c(111) : warning C4047: '!=' : 'int ' differs in levels of indirection from 'void *' c:\users\administrator\desktop\新建文件夹\123344\123.c(112) : error C2065: 'is_phone' : undeclared identifier c:\users\administrator\desktop\新建文件夹\123344\123.c(112) : error C2223: left of '->record' must point to struct/union c:\users\administrator\desktop\新建文件夹\123344\123.c(112) : error C2198: 'strcmp' : too few actual parameters c:\users\administrator\desktop\新建文件夹\123344\123.c(113) : error C2223: left of '->record' must point to struct/union c:\users\administrator\desktop\新建文件夹\123344\123.c(113) : error C2198: 'strcmp' : too few actual parameters c:\users\administrator\desktop\新建文件夹\123344\123.c(116) : error C2223: left of '->record' must point to struct/union c:\users\administrator\desktop\新建文件夹\123344\123.c(116) : warning C4033: 'search_record' must return a value c:\users\administrator\desktop\新建文件夹\123344\123.c(118) : error C2223: left of '->next' must point to struct/union c:\users\administrator\desktop\新建文件夹\123344\123.c(141) : error C2143: syntax error : missing ';' before 'type' c:\users\administrator\desktop\新建文件夹\123344\123.c(142) : error C2143: syntax error : missing ';' before 'type' c:\users\administrator\desktop\新建文件夹\123344\123.c(142) : error C2143: syntax error : missing ';' before 'type' c:\users\administrator\desktop\新建文件夹\123344\123.c(142) : error C2143: syntax error : missing ')' before 'type' c:\users\administrator\desktop\新建文件夹\123344\123.c(142) : error C2143: syntax error : missing ';' before 'type' c:\users\administrator\desktop\新建文件夹\123344\123.c(142) : error C2065: 'i' : undeclared identifier c:\users\administrator\desktop\新建文件夹\123344\123.c(142) : warning C4552: '<' : operator has no effect; expected operator with side-effect c:\users\administrator\desktop\新建文件夹\123344\123.c(142) : error C2059: syntax error : ')' c:\users\administrator\desktop\新建文件夹\123344\123.c(142) : error C2143: syntax error : missing ';' before '{' c:\users\administrator\desktop\新建文件夹\123344\123.c(144) : error C2065: 'used_buckets' : undeclared identifier c:\users\administrator\desktop\新建文件夹\123344\123.c(152) : error C2143: syntax error : missing ';' before 'type' c:\users\administrator\desktop\新建文件夹\123344\123.c(152) : error C2143: syntax error : missing ';' before 'type' c:\users\administrator\desktop\新建文件夹\123344\123.c(152) : error C2143: syntax error : missing ')' before 'type' c:\users\administrator\desktop\新建文件夹\123344\123.c(152) : error C2143: syntax error : missing ';' before 'type' c:\users\administrator\desktop\新建文件夹\123344\123.c(152) : warning C4552: '<' : operator has no effect; expected operator with side-effect c:\users\administrator\desktop\新建文件夹\123344\123.c(152) : error C2059: syntax error : ')' c:\users\administrator\desktop\新建文件夹\123344\123.c(152) : error C2143: syntax error : missing ';' before '{' c:\users\administrator\desktop\新建文件夹\123344\123.c(205) : error C2143: syntax error : missing ';' before 'type' c:\users\administrator\desktop\新建文件夹\123344\123.c(215) : error C2065: 'choice' : undeclared identifier c:\users\administrator\desktop\新建文件夹\123344\123.c(237) : error C2143: syntax error : missing ';' before 'type' c:\users\administrator\desktop\新建文件夹\123344\123.c(238) : error C2275: 'Record' : illegal use of this type as an expression c:\users\administrator\desktop\新建文件夹\123344\123.c(16) : see declaration of 'Record' c:\users\administrator\desktop\新建文件夹\123344\123.c(238) : error C2065: 'found' : undeclared identifier c:\users\administrator\desktop\新建文件夹\123344\123.c(238) : error C2065: 'search_length' : undeclared identifier c:\users\administrator\desktop\新建文件夹\123344\123.c(239) : warning C4047: 'function' : 'struct Record *' differs in levels of indirection from 'int ' c:\users\administrator\desktop\新建文件夹\123344\123.c(239) : warning C4024: 'print_record' : different types for formal and actual parameter 1 c:\users\administrator\desktop\新建文件夹\123344\123.c(249) : error C2143: syntax error : missing ';' before 'type' c:\users\administrator\desktop\新建文件夹\123344\123.c(250) : error C2275: 'Record' : illegal use of this type as an expression c:\users\administrator\desktop\新建文件夹\123344\123.c(16) : see declaration of 'Record' c:\users\administrator\desktop\新建文件夹\123344\123.c(251) : warning C4047: 'function' : 'struct Record *' differs in levels of indirection from 'int ' c:\users\administrator\desktop\新建文件夹\123344\123.c(251) : warning C4024: 'print_record' : different types for formal and actual parameter 1 c:\users\administrator\desktop\新建文件夹\123344\123.c(261) : error C2143: syntax error : missing ';' before 'type' c:\users\administrator\desktop\新建文件夹\123344\123.c(262) : error C2275: 'Record' : illegal use of this type as an expression c:\users\administrator\desktop\新建文件夹\123344\123.c(16) : see declaration of 'Record' c:\users\administrator\desktop\新建文件夹\123344\123.c(263) : warning C4047: 'function' : 'struct Record *' differs in levels of indirection from 'int ' c:\users\administrator\desktop\新建文件夹\123344\123.c(263) : warning C4024: 'print_record' : different types for formal and actual parameter 1 c:\users\administrator\desktop\新建文件夹\123344\123.c(273) : error C2143: syntax error : missing ';' before 'type' c:\users\administrator\desktop\新建文件夹\123344\123.c(274) : error C2275: 'Record' : illegal use of this type as an expression c:\users\administrator\desktop\新建文件夹\123344\123.c(16) : see declaration of 'Record' c:\users\administrator\desktop\新建文件夹\123344\123.c(275) : warning C4047: 'function' : 'struct Record *' differs in levels of indirection from 'int ' c:\users\administrator\desktop\新建文件夹\123344\123.c(275) : warning C4024: 'print_record' : different types for formal and actual parameter 1 2357.cpp 执行 cl.exe 时出错.”应该如何修改?完整版的代码是什么?
最新发布
11-05
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值