This answer will be updated due to C++11 extern template. Watch this space for updates in the near future!!
The C++ keyword export was originally designed to eliminate the need
to include a template
definition (either by providing the definition in the header file or by
including the implementation file). However, only a few compilers ever
supported this capability, such as
Comeau C++ and
Sun
Studio, and the general concensus was that it was not worth the
trouble.
Because of that, the C++11 standardization committee has voted to remove the
export feature from the language. Assuming this meets final approval,
export will remain a reserved word but it will no longer have any
meaning in the standard.
If you are working with a compiler that supports the export keyword,
it will probably continue to support the keyword via some sort of compiler
option or extension until its users migrate away from it. If you already have
code that uses export, you can use a fairly simple discipline to allow
your code to easily migrate if/when your compiler stops supporting it
entirely. Just define your template header-files like this:
// File Foo.h
#ifdef USE_EXPORT_KEYWORD
export
#endif
template<typename T>
class Foo {
...
};
#ifndef USE_EXPORT_KEYWORD
#include "Foo.cpp"
#endif
And define your non-inline functions in a source-file like this:
// File Foo.cpp
#ifdef USE_EXPORT_KEYWORD
export
#endif
template<typename T> ...
Then compile with
-DUSE_EXPORT_KEYWORD, or whatever equivalent
compiler option lets you set a preprocessor symbol like
USE_COMPILER_KEYWORD, and if/when your compiler removes support for
export, just remove that compiler option.