300字范文,内容丰富有趣,生活中的好帮手!
300字范文 > 错误提示:error LNK2001: unresolved external symbol public: static int person::weight (?weight@person@@

错误提示:error LNK2001: unresolved external symbol public: static int person::weight (?weight@person@@

时间:2022-05-02 01:52:33

相关推荐

错误提示:error LNK2001: unresolved external symbol public: static int person::weight (?weight@person@@

类中静态变量未初始化或初始化错误。(类中静态变量初始化方法:静态数据成员在类声明中声明,在包含类方法的文件中初始化.初始化时使用作用域操作符来指出静态成员所属的类.但如果静态成员是整型或是枚举型const,则可以在类声明中初始化!!!)

如:

头文件:class person

{

public:

person();

~person();

int Getheight();

int Getweight();

int height;

static int weight;

};

实现文件:#include "a.h"

int person::weight = 0;//静态成员初始化格式

person::person()

{

height = 100;

weight = 100;

}

错误提示:error LNK2001: unresolved external symbol "public: static int person::weight" (?weight@person@@2HA)

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。