C++编译错误"a storage class can only be specified for objects and functions"解决
2013-02-19 20:28
861 查看
对于这个错误,顾名思义,就是"storage class"的修饰符用在了对象或者变量(objects)和函数(functions)外的其他地方。
在C/C++规范中,定义了四种storage class的修饰符。
auto
register
static
extern
我所遇到的这个编译错误所对应的代码是下面所示。
class CDataSet{
public:
static enum ePrintRange
{
ALLDATA = 0,
......
}
......
}
(本人在学习STL,从互联网上找来一些例子学习,本人在编译某个例子的过程中遇到这个问题)
很显然,是这个"static"用的地方不对。查找了好多C++书籍和比较权威的解释,都指出这个"static"只能用于object和function。这个static用于修饰class的storage,很明显是错误的。去掉这个static,编译通过。
在Java中确实支持在某个类中定义一个内部static类,而Java的大部分语法的语义与C++比较接近,也许写这个例子的牛人想当然的认为C++中应该也有内部static类。
说句题外话,从网上看到C++的例子后,如果觉得有疑惑的话,就不妨编译一下,总有收获的:或者加深了对原来知识的理解,或者学到了新的技术。
还有在使用extern class a;的时候也会出现这样的提示。
在C/C++规范中,定义了四种storage class的修饰符。
auto
register
static
extern
我所遇到的这个编译错误所对应的代码是下面所示。
class CDataSet{
public:
static enum ePrintRange
{
ALLDATA = 0,
......
}
......
}
(本人在学习STL,从互联网上找来一些例子学习,本人在编译某个例子的过程中遇到这个问题)
很显然,是这个"static"用的地方不对。查找了好多C++书籍和比较权威的解释,都指出这个"static"只能用于object和function。这个static用于修饰class的storage,很明显是错误的。去掉这个static,编译通过。
在Java中确实支持在某个类中定义一个内部static类,而Java的大部分语法的语义与C++比较接近,也许写这个例子的牛人想当然的认为C++中应该也有内部static类。
说句题外话,从网上看到C++的例子后,如果觉得有疑惑的话,就不妨编译一下,总有收获的:或者加深了对原来知识的理解,或者学到了新的技术。
还有在使用extern class a;的时候也会出现这样的提示。
相关文章推荐
- C++编译错误"a storage class can only be specified for objects and functions"解决方法
- 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.”的编译错误
- 错误处理--pure specifier can only be specified for functions
- Entity Framework 中 使用Include 解决ObjectContext instance has been disposed and can no longer be used for operations that require a connection错误 -原创
- 错误“a label can only be part of a statement and a declaration is not a statement”解决方法
- Eclipse之NDK编译-- Type 'jint' could not be resolved, and JNIEnv, jclass错误解决办法
- 编译错误storage class specified for parameter XXX
- pure specifier can only be specified for functions
- pure specifier can only be specified for functions
- 出现"eh.h is only for C++!"错误的解决方法
- 如何解决"ANSI C++ forbids data member `ip_opts' with same name as enclosing class"的编译错误
- An explicit value for the identity column in table can only be specified when a column list is used and IDENTITY_INSERT is ON
- 错误“a label can only be part of a statement and a declaration is not a statement”解决方法
- storage class specified for parameter 编译错误
- 现"eh.h is only for C++!"错误的解决方法
- codeblocks进行C++开发 向工程中添加Class 发生编译错误:"No such file or directory" 解决方案
- 【完美解决】arcgis engine 10.0 for cross platform C++ 在visual studio2010上编译的AE程序 的License无法初始化错误。
- 关于IAR报 more than one storage class may not be specified 错误的问题
- 解决内核编译时产生 "mkimage" command not found - U-Boot images will not be built 错误
- switch引发的错误 a label can only be part of a statement and a declaration is not a statement