C++请教,不知道怎么样改错

C++语言 码拜 7年前 (2017-04-24) 867次浏览
#include <iostream.h>
#include <string.h>
class Person{
public:
char m_strName[20];
long m_ID;
public:
Person(char*strName,long ID)
{strcpy (m_strName,strName);m_ID=ID;}
static long GetID()
{return m_ID;}
};
void main()
{
Person person1(“LiuJun”,1101640524);
cout <<“ID=”<<Person::GetID()<<“\n”;
}
error C2597: illegal reference to data member “Person::m_ID” in a static member function
Error executing cl.exe.
解决方案

15

static long GetID()
{return m_ID;}
要对应:
static long m_ID;
不过你的题意不是这样,所以都去掉static吧。

50

静态成员函数不能返回非静态成员变量
static long GetID()
改成
long GetID()

CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明C++请教,不知道怎么样改错
喜欢 (0)
[1034331897@qq.com]
分享 (0)