C++模板编程
非常重要,因为你随便写一段代码在Visual C++和Dev C++里编译都可能遇到~~~
!!!!!![35.14] How does the C++ keyword export help with template
linker errors? Updated!
[Recently fixed a bug in the last paragraph by changing
NO_EXPORT_KEYWORD to USE_EXPORT_KEYWORD thanks to Luís Bruno (in
9/06). Click here to go to the next FAQ in the "chain" of recent
changes.]
The C++ keyword export is 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, at the time of
this writing, the only well-known compiler that supports this
capability is Comeau C++. The future of the export keyword is unknown.
Without taking sides in the debate, I will simply report that some
compiler vendors are indicating they might never implement it, and
that the C++ standards committee has decided to leave it in.
If you want your code to work with compilers that do not support the
export keyword, yet to also take advantage of the export keyword with
compilers that support it, define your template header-files like
this:
// File Foo.h
template<typename T>
class Foo {
...
};
#ifndef USE_EXPORT_KEYWORD
#include "Foo.cpp"
