Answer the question
In order to leave comments, you need to log in
Templates in cpp, what and how?
How to separate the implementation of a template from its declaration?
For example:
queue.h:
template<class T> queue{
struct item{
atomic<T> itm
item*next
}
queue();
push();
pop();
~queue();
}
template<typename T>
queue<T>::queue()
{
Head=new qq;
End=Head;
}
template<typename T>
void queue<T>::push(T* item){
try{
Logger("Function::%s position:%s:%i",__FUNCTION__,__FILE__,__LINE__);
item* t=new item;
t->item=NULL;
t->next=NULL;
End->itm=new atomic<T*>;
End->itm->store(item);
End->next=t;
End=End->next;
}
catch(...){
Exout("Exception::%s position:%s:%i",__FUNCTION__,__FILE__,__LINE__);
throw;
}
}
и т.д.
Answer the question
In order to leave comments, you need to log in
If the Ts to be used are known in advance, you can explicitly instantiate the required types in queue.cpp .
For example:
template class queue<int>;
And what should the compiler compile from the cpp file? What is the object file?
The implementation of template methods / functions cannot be moved to a separate translation unit, follow the advice of Chaos_Optima
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question