Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

c++ extern template instantiation and typedef (gcc)

I am trying to instantiate a template externaly however I would like o use a typedef in the instantiation clause. I think the example says more than thousand words:

typedef myTemplate_base<commonValue> myTemplate; //in 99% of the cases I use this so I want a shorthand
extern template class myTemplate; //wont work/compiler error class infront of typedef

I get the same error if I try to actually instantiate the template like this:

template class myTemplate;

I know I can write (extern) template class myTemplate_base<commonValue> instead, however I think this is uglier, since I need to adjust my common Value in 3 places instead of one.

So how do I have to put this, to use the typedef in the extern declaration/instantiation?

I am ussing gcc 4.6.1 on Ubunutu

like image 532
ted Avatar asked Dec 28 '22 09:12

ted


1 Answers

typedef-name cannot be used in explicit instantiation.

From 14.7.2/3

If the explicit instantiation is for a class or member class, the elaborated-type-specifier in the declaration shall include a simple-template-id. If the explicit instantiation is for a function or member function, the unqualifiedid in the declaration shall be either a template-id or, where all template arguments can be deduced, a template-name or operator-function-id. ...

like image 122
fefe Avatar answered Jan 12 '23 17:01

fefe