Dostęp do statycznego pola.

0

Witam,
w jaki sposób mógłbym się dostać do tego pola?

 static std::array<std::vector<Raport*>, static_cast<size_t>(ErrorLevel::Count)> mLog;

Próbuję zrobić coś na wzór "wewnętrznego singletona".

//LogRaport.hpp
class LogRaport : public TISingleton<LogRaport>
{
public:
          .......
	static void push(Raport raport, ErrorLevel level = ErrorLevel::Error);
          .......
	std::vector<Raport*>& operator()(const ErrorLevel &level);

private:
	static std::array<std::vector<Raport*>, static_cast<size_t>(ErrorLevel::Count)> mLog;
}; 
//LogRaport.cpp
void LogRaport::push(Raport raport, ErrorLevel level)
{
	instance->mLog[static_cast<size_t>(level)].push_back(&raport);
}
//TISingleton.hpp
using std::call_once;
using std::once_flag;

template<class T>
class TISingleton
{
protected:
	explicit TISingleton<T>() {}
	~TISingleton<T>() {}

protected:
	static std::unique_ptr<T> instance;
	static once_flag& get_once_flag() {
		static once_flag once_;
		return once_;
	}
};

template<class T> std::unique_ptr<T> TISingleton<T>::instance = nullptr;

W jaki sposób mogę to poprawić ?

Edit: Otrzymuję taki błąd

Error	LNK2001	unresolved external symbol "public: static class std::array<class std::vector<struct Raport *,class std::allocator<struct Raport *> >,3> LogRaport::mLog" (?mLog@LogRaport@@2V?$array@V?$vector@PAURaport@@V?$allocator@PAURaport@@@std@@@std@@$02@std@@A)	
1

Pola statyczne trzeba inicjalizować, więc dodaj taką linię w pliku .cpp:

std::array<std::vector<Raport*>, static_cast<size_t>(ErrorLevel::Count)> LogRaport::mLog;
0

używaj przestrzeni nazw using namespace std;

2
sidmas napisał(a):

używaj przestrzeni nazw using namespace std;

Nie, nie używaj tego. A tym bardziej w pliku h.

0

Głównie chodziło mi o to żebyś nie musiał pisać std cały czas natomiast przedmówcy mają racje. Sorki za wprowadzenie w błąd

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