Topic: A rant about name lookup in derived classes
Author: Valentin Bonnard <Bonnard.V@wanadoo.fr>
Date: 1999/10/21 Raw View
I have just had a problem w/ a library implementation
because it used unqualified inherited type names:
template <...>
struct foo : bar<...>
{
pointer baz ();
};
of course it doesn't work, and I have to:
- either qualify every occurence of the type names
- or re-typedef them once:
template <...>
struct foo : bar<...>
{
typedef typename foo::pointer pointer;
pointer baz ();
};
...same problem for inherited functions, with same
alternatives.
I don't think that anyone intentionally writes
code as follow:
typedef int U;
template <typename> struct B { typedef float U; }
template <> struct B<int> { };
template <typename X> struct D : B<X> {
U* foo ();
};
D<int> d;
int *pi = d.foo ();
and I don't think that the standard should make
efforts to support such code; OTOH, I often write
code that way:
template <typename> struct B2 { typedef float U; }
template <typename X> struct D2 : B2<X> {
U* foo ();
};
and I think that it's a pain to have to qualify
inherited members, especially when one derives from
a class just to get typedefs (unary_function).
I think it would have been a better rule for members
to be looked-up in the primary form of the base class,
so in the above example an unqualified U in D<> would
refer to B<X>::U, not ::U.
It would also be ill-formed, no diagnostic required,
to make something a type in one specialisation (or in
the primary template) and a non-type in another. (Does
anyone want to do THAT, anyway ?)
--
Valentin Bonnard
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://reality.sgi.com/austern_mti/std-c++/faq.html ]