Topic: Templates, typedef, and typename problem


Author: James Kuyper <kuyper@wizard.net>
Date: 1999/03/09
Raw View
Edward Diener wrote:
>
> I am dealing with a template declaration that, simplified, looks like
> this:
>
> template <class A, class B>
> class myclass
> {
> typedef B::tempinst<A>::memclass::ztype ztype;
> .... etc.
> };

You need to insert the 'typename' keyword, so that the compiler knows
that tempinst, memclass, and ztype are all types, not members.
---
[ 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: Edward Diener <eddielee@abraxis.com>
Date: 1999/03/04
Raw View
Biju Thomas wrote:

> Edward Diener wrote:
> >
> > template <class A, class B>
> > class myclass
> > {
> > typedef B::tempinst<A>::memclass::ztype ztype;
>
> You need the 'typename' specifier here for the compiler to understand
> that 'ztype' is a type. By default, it is assumed to be a non-type.
>
>  typedef typename B::tempinst<A>::memclass::ztype ztype;

The compiler didn't like this either and come up with an error message saying
that the declaration was terminated incorrectly. Sounds like a compiler bug.
---
[ 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: Biju Thomas <bijuthom@ibm.net>
Date: 1999/03/03
Raw View
Edward Diener wrote:
>
> template <class A, class B>
> class myclass
> {
> typedef B::tempinst<A>::memclass::ztype ztype;

You need the 'typename' specifier here for the compiler to understand
that 'ztype' is a type. By default, it is assumed to be a non-type.

 typedef typename B::tempinst<A>::memclass::ztype ztype;

> template <class A, class B>
> class myclass
> {
> typename B::tempinst<A>::memclass::ztype ZT;

This is declaring a variable named 'ZT' of type
B::tempinst<A>::memclass::ztype.

> typedef ZT ztype;

So, this statement is illegal.

--
Best regards,
Biju Thomas
---
[ 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: Patrick =?iso-8859-1?Q?M=E9rissert=2DCoffini=E8res?= <pamc@club-internet.fr>
Date: 1999/03/03
Raw View
I would think that the real ly standard syntax is:
  typedef typename B::template tempinst<A>::memclass::stype ztype;
yet the egcs-1.1.1 compiler accepts also:
  typedef typename C::tempinst<A>::memclass::stype ztype;

egcs-1.0.x accepts nothing at all, so I think this needs compilers quite
up-to-date as fas as the iso standard is concerned.
The publication of the final standard is not yet one year old, so such
compilers are, at best, quite rare.


Edward Diener wrote:

> I am dealing with a template declaration that, simplified, looks like
> this:
>
> template <class A, class B>
> class myclass
> {
> typedef B::tempinst<A>::memclass::ztype ztype;
> .... etc.
> };
>

Lots of cut text, to avoid the post failing by "More included text than new
text", sorry :-)
---
[ 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: Edward Diener <eddielee@abraxis.com>
Date: 1999/02/28
Raw View
I am dealing with a template declaration that, simplified, looks like
this:

template <class A, class B>
class myclass
{
typedef B::tempinst<A>::memclass::ztype ztype;
.... etc.
};

When the template gets instantiated all the internal types will be
resolved.

My compiler barfs on the ztype line claiming the declaration is
terminated incorrectly. When I try:

template <class A, class B>
class myclass
{
typename B::tempinst<A>::memclass::ztype ZT;
typedef ZT ztype;
.... etc.
};

I also get an error regarding a duplicate type. What is the method for
specifying types in a complicated expression such as the one above so
that when the compiler parses the template declaration prior to
instantiation, it does not produce a compiler error. My compiler claims
to support templates accordingly to the C++ standard as it officially
exists today.



[ 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              ]