I'm facing LNK2019 error: unresolved external symbol on some_container methods (including constructor and destructor) while trying to build my project.
This comes from my template class:
some_container.hpp
#include <unordered_set>
namespace name_space {
template<typename T> class some_container {
private: static std::unordered_set<T> some_set;
public:
some_container();
~some_container();
static const bool insert(T item);
}
}
some_container.cpp
#include "some_container.hpp"
using namespace name_space;
template<typename T>
some_container<T>::some_container() {
}
template<typename T>
some_container<T>::~some_container() {
}
template<typename T>
const bool some_container<T>::insert(T item) {
auto pair = some_container::some_set.insert(T); //Something wrong here?
return pair.second;
}
When some class inherits, this is how it's done:
class MyClass : private some_container<std::vector<int>*> {
//...
}
EDIT:
I tried moving all the implementation to my .hpp file, outside class and within the namespace. But now I'm getting another error:
LNK2001: unresolved external symbol on some_set (static data member inside some_container) class.
EDIT 2: Above issue has been fixed by changing it to "inline static". I'm not sure if it's the best approach though.