Topic: cross-module template instantiation
Author: Philip Gruebele <philipg@hpl.com>
Date: 1996/04/29 Raw View
I can't seem to be able to find much information on instantiating templat=
e=20
classes/functions accross module boundaries. Is this something that is b=
eing=20
addressed by the standard?
I want to create a class library which is provided through an Win32 DLL u=
sing=20
VC++ 4.1. I do not want to provide the source code of all the functions =
to=20
the clients. However, several classes are templetatized, and I cannot pr=
edict=20
which template parameters will be used.
To quote the VC++ documentation:
**********************************************
Microsoft Specific =AE
Templates are not officially standardized and, as a result, different C++=
=20
compiler vendors have implemented them differently. The following list sh=
ows=20
some differences between this version of Visual C++ and other compilers. =
Note=20
that this list will change in future versions of the compiler.
=B7 The compiler cannot instantiate a template outside of the module in=20
which it is defined.
=B7 Templates cannot be used with functions declared with __declspec=20
(dllimport) or __declspec (dllexport).
=B7 All template arguments must be of an unambiguous type that exactly=20
matches that of the template parameter list. For example:
=20
template< class T > T check( T );
template< class S > void watch( int (*)(S) );
watch( check ); //error
=20
The compiler should instantiate the check templated function in the=20
form int check( int ), but the inference can not be followed.
=B7 Friend functions must be declared before they are used in a templated=
=20
class. You cannot have a friend function defined within a class definitio=
n.=20
This is because the friend function could be a templated function, which =
would=20
cause an illegal nested template definition.
END Microsoft Specific
****************************************=09
This seems to be a major problem. How does the standard address this. A=
re=20
there any potential workarounds?
-phil
[ comp.std.c++ is moderated. To submit articles: try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ FAQ: http://reality.sgi.com/employees/austern_mti/std-c++/faq.html ]
[ Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html ]
[ Comments? mailto:std-c++-request@ncar.ucar.edu ]