pure specifier can only be specified for functions
来源:互联网 发布:js数组slice 编辑:程序博客网 时间:2024/06/09 18:47
源码:版本vc6.0
class CTest{private:int index = 0;char* name = NULL;public:void setname(char* str);};void CTest::setname(char* str){name = str;printf("%s",name);}int main(int argc, char* argv[]){CTest tt;char* name = "Hello,kitty!\n";tt.setname(name);return 0;}
编译后提示:
--------------------Configuration: Demo_1 - Win32 Debug--------------------Compiling...Demo_1.cppE:\SAVES\VC\Start\Demo_1\Demo_1.cpp(12) : error C2252: 'index' : pure specifier can only be specified for functionsE:\SAVES\VC\Start\Demo_1\Demo_1.cpp(13) : error C2252: 'name' : pure specifier can only be specified for functionsE:\SAVES\VC\Start\Demo_1\Demo_1.cpp(18) : error C2065: 'name' : undeclared identifierE:\SAVES\VC\Start\Demo_1\Demo_1.cpp(18) : error C2440: '=' : cannot convert from 'char *' to 'int' This conversion requires a reinterpret_cast, a C-style cast or function-style castError executing cl.exe.Demo_1.exe - 4 error(s), 0 warning(s)
这里出问题的原因是:成员变量index和name在声明时被初始化了,将index=0和name=NULL的初始化去掉。即:
class CTest{private:int index;char* name;public:void setname(char* str);};
经Baidu还有一个可能的原因是静态成员变量的原因,具体见http://blog.csdn.net/zxxyyxf/article/details/6432612
、
- pure specifier can only be specified for functions
- pure specifier can only be specified for functions
- pure specifier can only be specified for functions
- C++编译错误"a storage class can only be specified for objects and functions"解决
- C++编译错误"a storage class can only be specified for objects and functions"解决方法
- An explicit value for the identity column in table 'users' can only be specified when a column list
- error C2253: 'RefCounted<T>' : pure specifier or abstract override specifier only allowed on virtual
- java.lang.IllegalArgumentException: FormUrlEncoded can only be specified on HTTP methods with requ
- Error: Q0466E: An output file can only be specified if there is a single input file
- 【BCB】ocidl.h E2337 Only one of a set of overloaded functions can be ”C“ 报错解决办法
- Only one expression can be specified in the select list when the subquery is not introduced with(求助)
- Only one expression can be specified in the select list when the subquery is not introduced with EXI
- A script engine for the specified language can not be created
- Can functions be defined below return statements
- '?' can only be specfied for Day-of-Month -OR- Day-of-Week.
- How can the 'pure virtual method called' error be reproduced
- Only a type can be imported
- Why only SIP INVITE can be CANCELed ?
- POJ 1155(TreeDP)
- 有关View的几个基础知识点-IOS开发
- Oracle中文乱码解决思路
- hdu 1042 N!
- XHProf安装使用笔记
- pure specifier can only be specified for functions
- [Puzzle toad 3] Take the last chip
- JAVA计算器【源码】
- magento 积分插件 J2T Reward Points + Referral program VA 下载
- 类似VM菜单的简单实现
- Magento 导入导出分类插件Category Import Export使用教程
- [泛型经典]Java5泛型的用法,T.class的获取和为擦拭法站台
- 正则验证身份证
- Treasure Exploration----有路径重叠的最小路径覆盖