[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Templated method call problem
From: |
jon hanson |
Subject: |
Re: Templated method call problem |
Date: |
23 Sep 2004 04:31:49 -0700 |
Bernd Strieder <strieder@informatik.uni-kl.de> wrote in message
news:<ciscm7$38d$1@news.uni-kl.de>...
> Hello,
>
> the question and the answer belong into gnu.g++.help.
>
>
> jon hanson wrote:
>
> > template<typename X>
> > void test2 (const X&)
> > {
> > // This gives the error.
> > std::cout << "r=" << TagNames<X>::name<1> ();
>
> This should read
>
> std::cout << "r=" << TagNames<X>::template name<1> ();
>
> Due to two-phase lookup the compiler must interpret the code above as
> some comparisions between some member name and the number 1 compared to
> something behind, which stops to make any sense when reaching the empty
> braces.
>
> g++ 3.4 produces different error messages, which make equally littly
> clear, why the compiler cannot understand this. See gnu.gcc.org for the
> changes in g++ 3.4, there are some clear examples, when to insert those
> famous "template" and "typename" keywords. As soon as you are in a
> template, you have to take special care, i.e. you have to tell the
> compiler whether something is a dependent type or a template, which is
> only known at instantiation time (second phase of name lookup). OTW it
> will be interpreted as a member, like here, or something completely
> different at parsing time (first phase of lookup).
>
>
> Bernd Strieder
Bernd & the others - thanks for the help. I should have spotted that
however the cryptic error message foxed me.
Sorry if the example itself was a bit cryptic but it was a cutdown
version of the actual code which exhibited the problem and i didn't
want to post it in it's entirety.
I thought the code was otherwise standard conformant however i could
be wrong. The code in question has to compile on g++/linux,
Forte/Solaris, & VC/WinXp and since they're all at different levels of
lag behind the current standard writing conformant code is tricky at
the best of times.
jon