Topic: outline" template member


Author: wmm@fastdial.net
Date: 1999/06/03
Raw View
In article <7j5f40$2um$1@sturm.ign.fr>,
  "Gilles Roux" <roux@balafon.ign.fr> wrote:
> template <class T>
> class A
> { public :
>   template <class B> void func(B & obj) {...}
>   ...
> }
>
> The problem is that I can't manage to code the definition of the
member
> function outside the class. The following syntaxes doesn't work :
>
> template <class T>
> template <class B>
> void A<T>::func(B & obj) {...}
> ->compilation error
>
> template <class T, class B>
> void A<T>::func(B & obj) {...}
> -> linking error
>
> What's the right syntax ? Will it also work with gcc ?

The first syntax you used is correct (see 14.5.2 in the Standard,
which has an isomorphic example).

--
William M. Miller, wmm@fastdial.net
Software Emancipation Technology (www.setech.com)


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
---
[ 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    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]





Author: "Sam Lindley" <sam@redsnapper.net>
Date: 1999/06/03
Raw View
> > template <class T>
> > class A
> > { public :
> >   template <class B> void func(B & obj) {...}
> >   ...
> > }
> >
> > The problem is that I can't manage to code the definition of the
> member
> > function outside the class. The following syntaxes doesn't work :
> >
> > template <class T>
> > template <class B>
> > void A<T>::func(B & obj) {...}
> > ->compilation error
> >
> > template <class T, class B>
> > void A<T>::func(B & obj) {...}
> > -> linking error
> >
> > What's the right syntax ? Will it also work with gcc ?
>
> The first syntax you used is correct (see 14.5.2 in the Standard,
> which has an isomorphic example).
> [ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]

Unfortunately Visual C++ 6 doesn't support this feature, though.
The only way to use member templates inside a template class,
in VC++ 6, is to define the function inside the class declaration.

There are a number of issues with templates in VC++ 6. In
particular, I find the omission of the 'export' keyword particularly
annoying. This means all template functions must be defined in
the same translation unit as their declarations.
---
[ 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    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]





Author: "Gilles Roux" <roux@balafon.ign.fr>
Date: 1999/06/03
Raw View
Hi,

I'm using visual c++ 6 and I need to make a template member. The following
code works fine :

template <class T>
class A
{ public :
  template <class B> void func(B & obj) {...}
  ...
}

The problem is that I can't manage to code the definition of the member
function outside the class. The following syntaxes doesn't work :

template <class T>
template <class B>
void A<T>::func(B & obj) {...}
->compilation error

template <class T, class B>
void A<T>::func(B & obj) {...}
-> linking error

What's the right syntax ? Will it also work with gcc ?
Bye.

Gilles.
---
[ 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    ]
[              --- Please see the FAQ before posting. ---               ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html              ]