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

Why this does not compile?

P: n/a
Why this does not compile (gcc 3.4.2 and latest Comeau):

struct A
{
template<class T>
T f(int a)
{
return T(a);
}
};

template<class T>
double g()
{
T t;
return t.f<double>(3); // <-- here
}

int main()
{
g<A>();
}

In the marked place gcc says "error: expected primary-expression before
double".

cheers,
Marcin

Nov 4 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Marcin Kalicinski wrote:
Why this does not compile (gcc 3.4.2 and latest Comeau):

struct A
{
template<class T>
T f(int a)
{
return T(a);
}
};

template<class T>
double g()
{
T t;
return t.f<double>(3); // <-- here
}

int main()
{
g<A>();
}

In the marked place gcc says "error: expected primary-expression before
double".
...


Template members of dependent types have to be referred to with the explicit use
of keyword 'template'

template<class T>
double g()
{
T t;
return t.template f<double>(3);
}

--
Best regards,
Andrey Tarasevich
Nov 4 '05 #2

P: n/a
> Template members of dependent types have to be referred to with the
explicit use
of keyword 'template'

template<class T>
double g()
{
T t;
return t.template f<double>(3);
}

Thanks, that was quick!

Best regards,
Marcin
Nov 4 '05 #3

P: n/a
In article <bc*****************@newsfe2-win.ntli.net>,
Marcin Kalicinski <ka****@poczta.onet.pl> wrote:
Why this does not compile (gcc 3.4.2 and latest Comeau):

struct A
{
template<class T>
T f(int a)
{
return T(a);
}
};

template<class T>
double g()
{
T t;
return t.f<double>(3); // <-- here
}

int main()
{
g<A>();
}

In the marked place gcc says "error: expected primary-expression before
double".


Check out http://www.comeaucomputing.com/techt...templateprefix
--
Greg Comeau / Celebrating 20 years of Comeauity!
Comeau C/C++ ONLINE ==> http://www.comeaucomputing.com/tryitout
World Class Compilers: Breathtaking C++, Amazing C99, Fabulous C90.
Comeau C/C++ with Dinkumware's Libraries... Have you tried it?
Nov 5 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.