3

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?

R. Martinho Fernandes
  • 228,013
  • 71
  • 433
  • 510
Tony The Lion
  • 61,704
  • 67
  • 242
  • 415
  • "_Also why would an instantiation care about extern?_" Because that's the syntax used for an explicit instantiation declaration. Why would the compiler ignore valid syntax that changes the meaning of a decaration? Like `extern int i;` it says "this is a declaration, not a definition, there will be a definition somewhere in the program" – Jonathan Wakely Mar 11 '13 at 15:57

1 Answers1

6

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.

R. Martinho Fernandes
  • 228,013
  • 71
  • 433
  • 510