Go back to Richel Bilderbeek's homepage.

Go back to Richel Bilderbeek's C++ page.

 

 

 

 

 

(C++) extern template

 

extern template is a two-word keyword that has different meanings, depending on the standard used:

 

 

 

 

 

C++98 extern template in the C++98 standard

 

extern template is not supported in C++98.

 

 

 

 

 

C++11 extern template in the C++11 standard

 

 

extern template allows to forward declare template functions.

 

//Declaration in header (.h) file
extern template <class T> void Cout(const T& t);

//Definition in implementation (.cpp) file
template <class T> void Cout(const T& t)
{
  std::cout << t;
}

#include <string>

int main()
{
  Cout("Hello");
}

 

Technical note: the code shown did not compile using the G++ 4.4.5 compiler, which is supplied with the Qt Creator 2.0.0 IDE, but is expected to compile already (?) [1].

 

 

 

 

 

References

 

  1. GCC page about C++0x support

 

 

 

 

 

Go back to Richel Bilderbeek's C++ page.

Go back to Richel Bilderbeek's homepage.

 

Valid XHTML 1.0 Strict