help-gplusplus
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Templated method call problem


From: Bernd Strieder
Subject: Re: Templated method call problem
Date: Wed, 22 Sep 2004 19:27:35 +0200
User-agent: KNode/0.7.2

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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]