C++ Templates, typedefs, default template parameters

Mark Mitchell mark@markmitchell.com
Sat Oct 17 11:47:00 GMT 1998


  template< class T >
  class allocator
  {
  public:
    typedef T* pointer;
    //etc
  };

  template< class T, class A = allocator< T > >
  class block
  {
  public:
     typedef A allocator_type;
     typedef allocator_type::pointer pointer_type;

    pointer_type pBuffer;

  // etc

  };

  the compiler doesn't complain about the default template parameter (as, to
  be honest, I have come to expect). Instead, it reports:

  'A::pointer' is not a valid declarator.

Right; the standard requires:
 
  typedef typename allocator_type::pointer pointer_type;

Look for the section on dependent types in the standard.

  All this compiles fine on MSVC 5.0. _HORROR_ Can Microsoft really be
  sticking to a standard more closely than GNU?

Not this time...

-- 
Mark Mitchell 			mark@markmitchell.com
Mark Mitchell Consulting	http://www.markmitchell.com



More information about the Gcc-bugs mailing list