Reprise: Template syntax help

From: Dave (better_cs_now_at_yahoo.com)
Date: 08/10/04


Date: Tue, 10 Aug 2004 12:21:11 -0700


Hello,

Below, I have included a short program that does not compile. The
problematic line is indicated with a comment. Comeau produces this error:

"ComeauTest.c", line 19: error: type name is not allowed
        T::bar_t<int> local;
                 ^
Please note that the answer is *not* to preface the offending line with
"typename".

This is a problem with lookup of dependent names, and I think the
".template" construct is needed somehow. But I can't seem to get the right
syntax...

Thanks!
Dave

#include <iostream>

using namespace std;

struct foo_t
{
   template <typename T>
   struct bar_t
   {
      T m_var;
   };
};

template <typename T>
struct geeker
{
   void func()
   {
      T::bar_t<int> local; // Error here!

      local.m_var = 42;
      cout << local.m_var << endl;
   }
};

int main()
{
   geeker<foo_t> r;

   r.func();
}



Relevant Pages