Undefined reference to a static member

跟風遠走 提交于 2019-11-26 04:33:04

You need to define _frequency in the .cpp file.

i.e.

LARGE_INTEGER WindowsTimer::_frequency;
Vyktor

Linker doesn't know where to allocate data for _frequency and you have to tell it manually. You can achieve this by simple adding this line: LARGE_INTEGER WindowsTimer::_frequency = 0; into one of your C++ sources.

More detailed explanation here

If there is a static variable declared inside the class then you should define it in the cpp file like this

LARGE_INTEGER WindowsTimer::_frequency = 0;

With C++17, you can declare your variable inline, no need to define it in a cpp file any more.

inline static LARGE_INTEGER _frequency;
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!