Topic: visibility of template parameter typedef
Author: rmaddox@isicns.com (Randy Maddox)
Date: Wed, 16 Apr 2003 14:11:59 +0000 (UTC) Raw View
stip@mathematik.uni-ulm.de (Alexander Stippler) wrote in message news:<3e9bda56@news.uni-ulm.de>...
> Hi,
>
> why are typedef's for template class parameters not visible for the
> definition of members?
>
> template <typename T>
> class A
> {
> public:
> typedef T SynonymForT;
>
> SynonymForT
> doSomething();
> }
>
> Why can't I write the following?
>
> template <typename T>
> SynonymForT
> A<T>::doSomething()
> {
> ...
> }
>
> regards,
> alex
>
You can. You just have to tell the compiler where the name
SynonumForT comes from, as shown below.
template <typename T>
A<T>::SynonymForT // minor change
A<T>::doSomething()
{
...
}
Randy.
---
[ 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://www.jamesd.demon.co.uk/csc/faq.html ]
Author: stip@mathematik.uni-ulm.de (Alexander Stippler)
Date: Wed, 16 Apr 2003 00:02:06 +0000 (UTC) Raw View
Hi,
why are typedef's for template class parameters not visible for the
definition of members?
template <typename T>
class A
{
public:
typedef T SynonymForT;
SynonymForT
doSomething();
}
Why can't I write the following?
template <typename T>
SynonymForT
A<T>::doSomething()
{
...
}
regards,
alex
---
[ 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://www.jamesd.demon.co.uk/csc/faq.html ]
Author: leif.lonnblad@thep.lu.se (Leif Lonnblad)
Date: Wed, 16 Apr 2003 14:11:16 +0000 (UTC) Raw View
Alexander Stippler wrote:
> Hi,
>
> why are typedef's for template class parameters not visible for the
> definition of members?
>
> template <typename T>
> class A
> {
> public:
> typedef T SynonymForT;
>
> SynonymForT
> doSomething();
> }
>
> Why can't I write the following?
>
> template <typename T>
> SynonymForT
> A<T>::doSomething()
> {
> ...
> }
Because SynonymForT, just as doSomething(), is defined inside the class.
You need to write
template <typename T>
A<T>::SynonymForT
A<T>::doSomething()
{
...
}
/Leif
---
[ 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://www.jamesd.demon.co.uk/csc/faq.html ]
Author: bolo@softnrg.dnttm.ro ("Florian Preknya")
Date: Wed, 16 Apr 2003 14:11:49 +0000 (UTC) Raw View
"Alexander Stippler" <stip@mathematik.uni-ulm.de> wrote in message
news:3e9bda56@news.uni-ulm.de...
> Hi,
>
> why are typedef's for template class parameters not visible for the
> definition of members?
>
> template <typename T>
> class A
> {
> public:
> typedef T SynonymForT;
>
> SynonymForT
> doSomething();
> }
>
> Why can't I write the following?
>
> template <typename T>
> SynonymForT
> A<T>::doSomething()
> {
> ...
> }
>
Because SynonimForT type is defined inside the A class.
you have to write:
template <typename T>
A<T>::SynonymForT
A<T>::doSomething()
{
...
}
> regards,
> alex
>
> ---
> [ 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://www.jamesd.demon.co.uk/csc/faq.html ]
>
---
[ 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://www.jamesd.demon.co.uk/csc/faq.html ]
Author: v.Abazarov@attAbi.com ("Victor Bazarov")
Date: Wed, 16 Apr 2003 14:11:58 +0000 (UTC) Raw View
"Alexander Stippler" <stip@mathematik.uni-ulm.de> wrote...
> why are typedef's for template class parameters not visible for the
> definition of members?
They are, you're just not supplying enough information for them
to be "visible".
>
> template <typename T>
> class A
> {
> public:
> typedef T SynonymForT;
>
> SynonymForT
> doSomething();
> }
;
>
> Why can't I write the following?
>
> template <typename T>
> SynonymForT
> A<T>::doSomething()
> {
> ...
> }
Because 'SynonymForT' does not exist at _that_ scope. You need
to help the compiler to resolve the name:
template<typename T>
A<T>::SynonymForT
A<T>::doSomething()
{
...
}
'SynonymForT' is defined in the scope of the 'A' class template.
Victor
--
Please remove capital A's from my address when replying by mail
---
[ 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://www.jamesd.demon.co.uk/csc/faq.html ]