Неразрешенная внешняя символьная статическая переменная (переменная, используемая методом, определенным в заголовке)
Вот это .h:
class Logger
{
private:
static int mTresholdSeverity;
public:
static __declspec(dllexport) void log(const char* message);
static __declspec(dllexport) void logFormat(const char* format, ...);
static __declspec(dllexport) int getTresholdSeverity() { return mTresholdSeverity; }
static __declspec(dllexport) void setTresholdSeverity(int tresholdSeverity) { mTresholdSeverity = tresholdSeverity; }
};
И .cpp:
#include "Logger.h"
#include <cstdarg>
int Logger::mTresholdSeverity = 200;
void Logger::log(const char* message)
{
//...
}
void Logger::logFormat(const char* format, ...)
{
//...
}
Я получаю эту ошибку:
ошибка LNK2001: неразрешенный внешний символ & quot; private: static int TransformationViewer_Utility_Logging :: Logger :: mTresholdSeverity & quot; (? mTresholdSeverity @ Logger @ TransformationViewer_Utility_Logging @@ 0HA) ...
Очевидно, что mTresholdSeverity инициализируется. Ошибка удаляется, если я закомментирую getTresholdSeverity () и setTresholdSeverity () или если я перенесу их определение в файл .cpp.
Почему возникает ошибка ссылки, когда статический метод, определенный в заголовочном файле (getTresholdSeverity () или setTresholdSeverity ()), использует статическую переменную (mTresholdSeverity)?