1

The following code does not compile both in MSVC and GCC. It produces exactly opposite compiler behavior regarding the presence of the 'typename' keyword. MSVC requires that 'typename' is included before A::B<E>, otherwise an error is displayed, while GCC requires that the typename' keyword is removed. Is there a way to workaround this problem without using #ifdef/#endif blocks?

template <class C>
class A
{
   template <class D>
   class B
   {
   };

   template <class E>
   void get(typename A::B<E>& value)
   {
   }
};

int main(int argc, char *argv[])
{
    return 0;
}

MSVC output when 'typename' keyword is not present:

warning C4346: 'A<C>::?$B@$RCAAB@': dependent name is not a type
note: prefix with 'typename' to indicate a type
error C2061: syntax error: identifier 'B'

GCC output when 'typename' keyword is present:

error: 'typename A<C>::B' names 'template<class C> template<class D> class A<C>::B', which is not a type
bkxp
  • 1,115
  • 1
  • 12
  • 20

0 Answers0