pure specifier can only be specified for functions
ソース:バージョンvc 6.0
コンパイル後のヒント:
ここで問題が発生したのは、メンバー変数indexとnameが宣言時に初期化され、index=0とname=NULLの初期化が削除されたためです.次のようになります.
Baiduを経由してもう一つの可能性のある原因は静的メンバー変数の原因であり、具体的にはhttp://blog.csdn.net/zxxyyxf/article/details/6432612
、
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!
";
tt.setname(name);
return 0;
}
コンパイル後のヒント:
--------------------Configuration: Demo_1 - Win32 Debug--------------------
Compiling...
Demo_1.cpp
E:\SAVES\VC\Start\Demo_1\Demo_1.cpp(12) : error C2252: 'index' : pure specifier can only be specified for functions
E:\SAVES\VC\Start\Demo_1\Demo_1.cpp(13) : error C2252: 'name' : pure specifier can only be specified for functions
E:\SAVES\VC\Start\Demo_1\Demo_1.cpp(18) : error C2065: 'name' : undeclared identifier
E:\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 cast
Error 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
、