Hi to everyone,

In a VC6.0 project we have a class C which is exported in a dll.
We added a template member function, say C::f<T>(T x)


///// C.h

class IMPORT_EXPORT_DIRECTIVE C
{
// ...

template <typename T>
void f<T>(T x)
{
// body
}

};


since we only call f on a particular iterator, we added the following
line(s)

///// C.CPP

typedef std::multimap<double, long>::iterator mmiter_t;
template void C::f< mmiter_t >( mmiter_t );


VC6.0 gives up (internal compiler error) on the forced instantiation line.
We didn't try VC7.1 yet.
It it the correct solution?

--
Every idea yields an answer
-- Abercrombie Smith

Re: export a template method? by Patrik

Patrik
Wed Jul 30 04:38:31 CDT 2003


> class IMPORT_EXPORT_DIRECTIVE C
> {
> // ...
>
> template <typename T>
> void f<T>(T x)
try: void f(T x)
> {
> // body
> }
>
> };
>


Re: export a template method? by Carl

Carl
Wed Jul 30 09:07:17 CDT 2003

Mycroft Holmes wrote:
> Hi to everyone,
>
> In a VC6.0 project we have a class C which is exported in a dll.
> We added a template member function, say C::f<T>(T x)
>
>
> ///// C.h
>
> class IMPORT_EXPORT_DIRECTIVE C
> {
> // ...
>
> template <typename T>
> void f<T>(T x)
> {
> // body
> }
>
> };
>
>
> since we only call f on a particular iterator, we added the following
> line(s)
>
> ///// C.CPP
>
> typedef std::multimap<double, long>::iterator mmiter_t;
> template void C::f< mmiter_t >( mmiter_t );
>
>
> VC6.0 gives up (internal compiler error) on the forced instantiation
> line. We didn't try VC7.1 yet.
> It it the correct solution?

In principal, it's the correct solution. In practice, if you're stuck with
VC6, it'd no doubt be easier to simply supply a non-template overload of
C::f<T> that matches std::multimap<double,long>::iterator.

-cd