Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Explicit instantiation declaration with extern

I am reading 14.7.2 in C++ Standard draft n3485 and it says:

2 The syntax for explicit instantiation is: explicit-instantiation: externopt template declaration

There are two forms of explicit instantiation: an explicit instantiation definition and an explicit instantiation declaration. An explicit instantiation declaration begins with the extern keyword.

Seeing that a template declaration and definition is always put in a header, I have never seen a declaration with extern on a template. What exactly does that bolded sentence mean?

Also why would an instantiation care about extern?

like image 330
Tony The Lion Avatar asked Oct 28 '25 07:10

Tony The Lion


1 Answers

It tells the compiler not to instantiate that template in this TU.

Note that it should be instantiated in one TU (without the extern bit), if you want your code to actually link.

like image 161
R. Martinho Fernandes Avatar answered Oct 29 '25 20:10

R. Martinho Fernandes



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!