对静态成员的未定义引用 [英] Undefined reference to a static member
本文介绍了对静态成员的未定义引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用的是交叉编译器。我的代码是:
I'm using a cross compiler. My code is:
class WindowsTimer{
public:
WindowsTimer(){
_frequency.QuadPart = 0ull;
}
private:
static LARGE_INTEGER _frequency;
};
我得到以下错误:
未定义引用`WindowsTimer :: _ frequency'
undefined reference to `WindowsTimer::_frequency'
我也尝试将其更改为
LARGE_INTEGER _frequency.QuadPart = 0ull;
或
static LARGE_INTEGER _frequency.QuadPart = 0ull;
但我仍然收到错误。
任何人都知道为什么?
推荐答案
您需要定义 _frequency
.cpp文件。
You need to define _frequency
in the .cpp file.
即
LARGE_INTEGER WindowsTimer::_frequency;
这篇关于对静态成员的未定义引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文