James Kanze
10/10/2008 8:11:00 AM
On Oct 9, 1:26 pm, Juha Nieminen <nos...@thanks.invalid> wrote:
> jdmuys wrote:
> > The reason is that there is no unambiguous way to tell what
> > the "class1<Type>::X *p2" is until class1 is instanciated.
> > It can be two very different things:
> > 1- A pointer declaration, when X is a type inside class1.
> > This is the original intent.
> > 2- a multiplication (!!), when X is (for example), an int
> > member of class1. This could happen.
> When you want to specify option 1, you use the keyword
> 'typename'. However, how can you specify that you really want
> it to be interpreted as option 2?
> (Or is it so that it's by default interpreted as option 2,
> which causes the error because the parameters are not valid
> for the binary operator*, and you have to specify the
> 'typename' if you want to tell the compiler that this is a
> type declaration, not a call to operator*?)
The goal is that the compiler can reasonably parse a template
before any instantiation. To do this, practically, for each
symbol, it must know whether the symbol is bound to a type, a
template or something else. For dependent symbols (those whose
actual binding depends on the instantiation), the compiler
assumes something else, unless you tell it differently (typename
or template keywords). If, during actual instantiation, it
turns out that the assumption was wrong (you lied, or you forgot
to tell it), the program is ill-formed, and you get an error
message.
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34