I have a working code with a template. Like stl :: string, I mainly use my template with one parameter for several compilation units. To save time, I am trying to use extern instantiation . However, changing the lines as follows gives an error. What is the right way to do this? (PS Compiling on gcc with the C ++ 0x flag)
typedef myTemplate_base<commonType> myTemplate;
extern template class myTemplate_base<commonType>;
I added an additional cpp file with the following project.
template class myTemplate_base<commonType>;
An error message appears in the linker (providing the line of the first instance of the object ( myTemplate someVar;) in the main file as an error source):
undefined link 'myTemplate_base :: ~ myTemplate_base ()'
However, this type is in a class with the following definition ~myTemplate() = default;
Edit: If you have a better headline, comment on the comment, so the right people will take a look at this.
Edit2: . In a funny case, adding template class myTemplate_base<commonType>significantly increases the size of the executable file (+ 100k in the binary 450 thousand), although the template is used mainly (for compilation I have to comment on the part extern). This indicates that the linker supports two template implementations with the same instance / me, something is missing.
source
share