On Jan 1, 3:24 am, Barry <dhb2...@gmail.com> wrote:
yuanhp_ch...@hotmail.com wrote:
I define aclassin A.h:
template<classT>classA{
public:
void get_elem( const T&) ;
};
Then I give the implementation in A.cpp (and do anexplicit
instantiation):
Separating atemplateclassinto hxx file and cxx file should be done
with keyword 'export' support, which is rarely supported by compilers
(IIRC, Comeau supports it).
So when you define atemplateclass, just put all the implementation in
hxx files.
template<classT> void A::get_elem( const T&)
{...}
templateclassA<int>; //explicitinstantiation
I have another two files: main.cpp and B.cpp. I would like to reuse
theexplicitinstantiationof A<int> of A.cpp in the two files. Do I
need to declareclassA<int> in the two files? I am not sure how to do
it?
Don't worry about the duplicatedinstantiation, the compiler is smart
enough to know which she's already instantiated.
Any help are appreciated.
I think you should find a textbook to start withtemplateprogramming first.
Thanks for your reply. I have read many c++ books, but no one talk
the explicit instantiation very well.
I prefer to the explicit instantiation instead of inline. But when I
do an explicit instantiation in one .cpp file, I got some link error
when more than one files are needing to use the explicit instantiation
(if just one file, it can work.).
feature.