|
Boost : |
From: Daniel Frey (daniel.frey_at_[hidden])
Date: 2004-02-17 04:19:24
Gabriel Dos Reis wrote:
> David Abrahams <dave_at_[hidden]> writes:
>
> | > What is bizarre and inconsistent about it and is not with the other
> | > alternatives you care to name?
> |
> | As I expected my example below to demonstrate, I think it's
> | inconsistent with the way names from non-dependent base classes are
> | dealt with when masked by function parameter names.
>
> But function parameters are not template parameters vice versa. And
> you should not expect them to behave the same without providing
> technical reasons why such expectations may take place.
>
> The fundamental difference between them is the places where they are
> declared. The scope of template-parameters *encloses* the template --
> that is why members of non-dependent bases hide them -- whereas member
> functions *are enclosed* by the scope (non-dependent) base classes
> -- which is why those function parameters can hide members in base
> classes.
>
> An action that would be consistent is to leave the current rule as is
> -- but some people been saying that that consistent behaviour goes
> against their intuition.
Apologies in advance if I jump in too quickly without fully
understanding your point, but to me it seems that the current rule is
consistent only when viewed from a certain point of view. The POV is that
class B { typename X };
template< typename X > class Y // 1
: public B // 2
{ // 3
...
};
You think that template parameter X is declared in line 1, then hidden
by the base classes name introduced by line 2, thus non-accessible in
line 3, right? You think of the name scopes to nest in the same order,
do you? This is a reasonable point of view, actually it's the current
language's interpretation of the topic, but it's not what I call
intuitive. While it's technically correct, it still feels wrong - at
least to me. I see things more from a visibility-point-of-view. I can't
see the base class' names at 2, I have to go back (that is, I have to go
one "scope" up) to see the names that are contained. This makes me think
of the lines 1 and 2 to be swapped wrt the names they introduce into the
scope of 3. To put it another way: The names of B are not declared at 2,
and that line 2 is also not like a using declaration, although it might
seem similar.
If we use Dave's or my POV (and we are not alone ;), the advantages of
scopes can be used in this example, too. The advantage is a smaller
scope to search for a name: If you need to know what a name refers to,
you just look into the scopes from the inside (nearest scope), to the
outside. And it feels more natural to me if the scope of the template
parameters is closer than the scope of the class' base(s).
Regards, Daniel
[I CC'ed Daveed as he might be interested in this, too, and I'm not sure
if he's reading the boost list]
-- Daniel Frey aixigo AG - financial solutions & technology Schloß-Rahe-Straße 15, 52072 Aachen, Germany fon: +49 (0)241 936737-42, fax: +49 (0)241 936737-99 eMail: daniel.frey_at_[hidden], web: http://www.aixigo.de
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk