As far as I found, there were articles about initializing a static variables in class templates. However, I´m using a normal class with member function templates, so I have to ask.
In short version(not whole class definition) I have a class that look like this:
class BatchManager
{
private:
static std::vector<BaseBatch_P> _BATCHES;
public:
template <class T>
static void placeData(T* data){
//Loop through the entire container
for (auto&& b: _BATCHES)
if (b==data){
dynamic_cast<Batch<T>>(b)->draw(data);
}
//If no bach found, create a new One
createNewBatch(data);
}
};
However, when I want to access the member variables inside the function, it shows: undefined reference to BatchManager::_BATCHES
Then I´ve tried the following: keep definition in class header :
//BatchManager.h
template <typename T>
static void placeData(T* data);
And cpp file:
std::map<GLuint,BaseBatch_P> BatchManager::_TEXTURE_MAP;
template <typename T>
void BatchManager::placeData(T* data){
//Loop through the entire container
for (auto&& b: _BATCHES)
if (b==data){
dynamic_cast<Batch<T>>(b)->draw(data);
}
//If no bach found, create a new One
createNewBatch(data);
}
It fixes the first problem, but then another appears, and it happens when I want to call my static function from the program:
BatchManager::render(_data);
Error message looks like this:
undefined reference to BatchManager::placeData<DataType>(DataType*)
How can i fix this problem? Or am I doing something wrong?