typeof() in templates

Martin v. Loewis martin@mira.isdn.cs.tu-berlin.de
Mon Jul 26 14:56:00 GMT 1999


> template <class AParticle>
>  class World
>   {
>    typedef typeof(AParticle::origin) Position;
>    typedef typeof(AParticle::velocity) Velocity;
>         
>   }

Thanks for your bug report. I have a couple of comments.
gcc-2.95 19990717 does not crash anymore, instead it says

a.cc:5: sorry, not implemented: testing typeof_type for template parms

so it appears the bug is not that bad anymore.

Please note that "typeof" is a g++ extension, so you shouldn't use it
unless you have to. In your example, you don't *really* have to. Your
code assumes that AParticle has an origin member - you could just as
well assume that it has a OriginType member, i.e.

struct MyParticle{
  typedef int OriginType;
  OriginType origin;
  typedef double VelocityType;
  VelocityType velocity;
};

Then you can say

  typedef typename AParticle::OriginType Position;

which would be standard C++.

Hope this helps,
Martin



More information about the Gcc-bugs mailing list