C++编译错误"a storage class can only be specified for objects and functions"解决方法
2014-03-05 08:54
2086 查看
昨天在写积分器控制程序的时候,类里面定义了一个枚举类型,编译的时候出现了上述错误,造成错误的原因是在这个枚举类型前面有static修饰符,如下:
去掉前面的static编译通过。
对于这个错误,顾名思义,就是"storage class"的修饰符用在了对象或者变量(objects)和函数(functions)外的其他地方。
在C/C++规范中,定义了四种storage class的修饰符。
auto
register
static
extern
很显然,是这个"static"用的地方不对。查找了好多C++书籍和比较权威的解释,都指出这个"static"只能用于object和function。这个static用于修饰class的storage,很明显是错误的。去掉这个static,编译通过。
参见博客http://blog.csdn.net/weibin_168/article/details/6669736
static enum cmd{IntHelp,IntDelayCharge,IntDelayDisCharge,IntStandard,IntPulse};
去掉前面的static编译通过。
对于这个错误,顾名思义,就是"storage class"的修饰符用在了对象或者变量(objects)和函数(functions)外的其他地方。
在C/C++规范中,定义了四种storage class的修饰符。
auto
register
static
extern
很显然,是这个"static"用的地方不对。查找了好多C++书籍和比较权威的解释,都指出这个"static"只能用于object和function。这个static用于修饰class的storage,很明显是错误的。去掉这个static,编译通过。
参见博客http://blog.csdn.net/weibin_168/article/details/6669736
相关文章推荐
- C++编译错误"a storage class can only be specified for objects and functions"解决
- 出现"eh.h is only for C++!"错误的解决方法
- 现"eh.h is only for C++!"错误的解决方法
- DOUAudioStreamer在Xcode6.1中编译出现_OBJC_CLASS_$_DOUMPMediaLibraryAssetLoader",错误的解决方法。
- MPI编译C++程序出现#error "SEEK_SET is #defined but must not be for the C++ binding of MPI" 的解决方法
- MySQL "You can't specify target table 'X' for update in FROM clause" 错误解决方法
- 错误处理--pure specifier can only be specified for functions
- MPI编译C++程序出现#error "SEEK_SET is #defined but must not be for the C++ binding of MPI" 的解决方法
- 错误“a label can only be part of a statement and a declaration is not a statement”解决方法
- 错误“a label can only be part of a statement and a declaration is not a statement”解决方法
- .NET下编译C++代码时出现"error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int"错误的解决方法。
- VB6:关于“Only public user defined types defined in public object modules can be used as parameters or return types for public procedures of class modules or as fields of public user defined types.”的编译错误
- Unity关于 "Move" can only be called on an active agent that has been placed on a NavMesh.问题的解决办法
- 在VMware上编译linux内核出现VFS: Cannot open root device "LABEL=/" or unknown-block(0,0) 错误的解决方法
- Entity Framework 中 使用Include 解决ObjectContext instance has been disposed and can no longer be used for operations that require a connection错误 -原创
- 编译linux内核时出现"mkimage" command not found - U-Boot images will not be built错误的解决办法
- Eclipse之NDK编译-- Type 'jint' could not be resolved, and JNIEnv, jclass错误解决办法
- python "threads can only be started once"解决方法
- 解决内核编译时产生 "mkimage" command not found - U-Boot images will not be built 错误
- 错误“Unexpected namespace prefix "xmlns" found for tag LinearLayout”的解决方法