C ++ instance instance of template and typedef (gcc)

I am trying to instantiate a template, but I would like o to use typedef in the instantiation condition. I think the example says more than a 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 instantiate a template as follows:

 template class myTemplate; 

I know that I can write an (extern) template class myTemplate_base<commonValue> instead, however, I think it is ugly, since I need to adjust the total value in 3 places instead of one.

So, how do I do this to use typedef in an extern / instance declaration?

I am using gcc 4.6.1 on Ubunutu

+4
source share
2 answers

typedef-name cannot be used in an explicit instance.

From 14.7.2 / 3

If there is an explicit instantiation for a class or member class, the specified qualifier type in the declaration must include a simple identifier pattern. If there is an explicit instantiation for a function or a member function, those unqualified in the declaration should either have a template identifier or, where all template arguments can be inferred, a template name or an identifier for a function-function ....

+8
source

Use constexpr or typedef for your overall value. Then you only need to change the total value once, and all explicit instances will be changed.

What about the best you can do. You are not allowed to explicitly create an instance using the tyepdef name.

+2
source

Source: https://habr.com/ru/post/1387125/


All Articles