struct and class member alias

Stuart Murray stuart.w.murray at fakey.nospambots.gmail.com
Wed Jun 6 06:57:22 PDT 2007


Jarrett Billingsley Wrote:

> "Stuart Murray" <stuart.w.murray at fakey.nospambots.gmail.com> wrote in 
> message news:f458q0$2vea$1 at digitalmars.com...
> >
> > Interesting that it doesn't compile for you.. It definitely does for me 
> > (using DMD v1.014)
> > This is the example I referred to, if anyones interested:
> >
> > class A
> > {
> >    int foo(int x) { ... }
> >    int foo(long y) { ... }
> > }
> >
> > class B : A
> > {
> >    alias A.foo foo;
> >    override int foo(long x) { ... }
> > }
> >
> > Its in the documentation. As I said, it's slightly different thing, but it 
> > seems to .. *match*..
> 
> Oh, well _that_ will compile :)  It's because "A.foo" is not an expression, 
> it's a symbol.  You're saying "bring my superclass's implementation of foo 
> into this namespace so it can be overloaded."  A.foo is a name, so you can 
> alias it.  The "A." is just there as a marker to say where foo lives.
> 
> In your example, pos and size are class instances; they have no meaning 
> until they've been new'ed.  Furthermore, pos.x is not a symbol, it's an 
> expression -- it's an access to a member whose location can't be determined 
> at compile time.  So, you can't alias it. 
> 
> 

Thanks, that all seems to make sense. Thanks a lot for your help.
As a last note I would suggest that the example:

> > class A
> > {
> >    int foo(int x) { ... }
> >    int foo(long y) { ... }
> > }
> >
> > class B : A
> > {
> >    alias A.foo foo;
> >    override int foo(long x) { ... }
> > }

seems a bit of a hacky way to fix the overload choosing thing, I suspect most newcomers would assume that subclass member functions would overload with superclass members of the same name. But such is life.



More information about the Digitalmars-d-learn mailing list