This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Tool/software: TI C/C++ Compiler
Hello all! CCS 7.1/TI v16.9.1.LTS/TMS320F2812/
I am try to compile my template:
//ModBus.h
template <class T> class Collection
{
public:
static int count; //static declaration
Collection()
{
count++;
}
};
template<class T>
int Collection<T>::count;
//ModBus.cpp
#include "ModBus.h"
Collection<float> CollectionObject;
void ModBusTables_Init(void)
{
Collection<float>::count = 6;
}
I take compile msg
I found my situation on this page on chapter called Third Workaround: Use a Template in a Non-Template Class Declaration.
The user who uses my template should declare himself every static member for each type he wants to use in template parametr? I do not like this
How can i solve this problem? Thank you!
Write it like so:
class userModBusSegment: [blah] { private: [blah] static userModBusSegment *theUserSegment; [blah] public: [blah] userModBusSegment *UserSegment() { if (!theUserSegment) theUserSegment= new userModBusSegment(); return theUserSegment; } [blah] UserSegment()->Data_Size = [blah]; [blah] }; template userModBusSegment<T_DataStruct, T_DataType> * userModBusSegment<T_DataStruct, T_DataType>::theUserSegment = NULL;
There are other ways to implement Singleton, so don't take this as the only way to go.