静态成员和LNK错误在C ++ [英] static members and LNK error in C++
本文介绍了静态成员和LNK错误在C ++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个类有静态成员,我想在类构造函数中使用,但代码不编译,我留下这些错误:
致命错误LNK1120:1未解析的外部
LNK2001:未解析的外部符号protected:static class Collection A :: collection
任何帮助将被感激。
谢谢。
ah
class A
{
protected:
static Collection< A *>集合;
};
a.cpp
A :: A(){
A :: collection.push_back(this);
}
解决方案
您需要添加
; A *> A :: collection;
I have a class that has a static member, which I want to use in the class constructor, but the code doesn't compile, and I'm left with these errors:
"fatal error LNK1120: 1 unresolved externals"
"error LNK2001: unresolved external symbol "protected: static class Collection A::collection"
Any help will be appreciated. Thanks.
"a.h"
class A
{
protected:
static Collection<A*> collection;
};
"a.cpp"
A::A() {
A::collection.push_back(this);
}
解决方案
You need to add
Collection<A*> A::collection;
to your a.cpp file.
这篇关于静态成员和LNK错误在C ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文