"LNK2001 uresolved external symbol" przy dodaniu zmiennej static w klasie

0

mam problem przy tej klasie:

#pragma once
#include <GLFW/glfw3.h>
class Timer {
public:
	Timer();
	~Timer();

	void Tick();
	double GetElapsedSeconds();
private:
	static double previousSeconds;
	double currentSeconds;
	double elapsedSeconds;
};
#include "Timer.h"



Timer::Timer() {
	previousSeconds = 0;
	currentSeconds = 0;
	elapsedSeconds = 0;
}


Timer::~Timer() {
}

void Timer::Tick() {
	previousSeconds = glfwGetTime();
	currentSeconds = glfwGetTime();
	elapsedSeconds = currentSeconds - previousSeconds;
	previousSeconds = currentSeconds;
}

double Timer::GetElapsedSeconds() {
	return elapsedSeconds;
}

Gdy kompiluje program wyskakuje mi błąd

Severity	Code	Description	Project	File	Line	Suppression State
Error	LNK2001	unresolved external symbol "public: static double Timer::previousSeconds" (?previousSeconds@Timer@@2NA)	Renderer	D:\Projekty\OpenGL_Renderer\Renderer\Renderer\Timer.obj	1	

problem nie występuje gdy usunę przy zmiennej *previousSeconds *słowo static
W pozostałej części programu jest tylko tworzony obiekt klasy, więc chyba nie ma sensu dodania tego, by tylko zaciemniło.
Nie wiem co jeszcze może się przydać, żeby spróbować rozwiązać ten problem.

1
#include "Timer.h"

// Zmienne statyczne dla klasy trzeba określać w ten sposób:
double Timer::previousSeconds = 0;

Timer::Timer() {
    previousSeconds = 0;
    currentSeconds = 0;
    elapsedSeconds = 0;
}

// ...

edit: Krótko mówiąc, gdy tworzysz zmienną statyczną wymagana jest nie tylko jej deklaracja, ale także nadanie jej wartości w pliku źródłowym. Pamiętaj tylko o określeniu klasy z której pochodzi.

0

Dziękuję, działa

1 użytkowników online, w tym zalogowanych: 0, gości: 1