By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,944 Members | 1,299 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,944 IT Pros & Developers. It's quick & easy.

Reprise: Template syntax help

P: n/a

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();
}

Jul 22 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
On Tue, 10 Aug 2004 12:21:11 -0700, Dave wrote:

Please note that the answer is *not* to preface the offending line with
"typename". 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!


This works:

typename T:: template bar_t<int> local;

Ali
Jul 22 '05 #2

P: n/a
Dave wrote:
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!
VC++ accepts it without 'template', but Comeau shuts up if I say

typename T:: template bar_t<int> local; // Error here!

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

int main()
{
geeker<foo_t> r;

r.func();
}


"If at first you don't succeed, try and try again..."

V
Jul 22 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.