Undefined Reference to a Static Member
This error occurs when the compiler cannot find the definition of a static member variable. In this case, it pertains to the static member variable _frequency of the WindowsTimer class.
Understanding the Code
The code presented is:
class WindowsTimer { public: WindowsTimer() { _frequency.QuadPart = 0ull; } private: static LARGE_INTEGER _frequency; };
Here, _frequency is a static member variable of type LARGE_INTEGER, which is declared but not defined within the class.
Resolving the Error
The error message "undefined reference to WindowsTimer::_frequency" indicates that the compiler cannot find the definition of _frequency. Static member variables must be defined outside the class declaration, typically in the implementation (.cpp) file.
To resolve the error, add the following definition to the .cpp file:
LARGE_INTEGER WindowsTimer::_frequency;
This will create a global variable of type LARGE_INTEGER named _frequency that is linked to the WindowsTimer class.
Why the Other Changes Didn't Work
The above is the detailed content of Why Does 'undefined reference to WindowsTimer::_frequency' Occur and How Is It Fixed?. For more information, please follow other related articles on the PHP Chinese website!