Jump to page: 1 2 3
Thread overview
interfaces
Feb 02, 2002
Pavel Minayev
one more thing
Feb 02, 2002
Pavel Minayev
Feb 02, 2002
Walter
Feb 02, 2002
Pavel Minayev
Feb 02, 2002
Walter
and more... =)
Feb 02, 2002
Pavel Minayev
Feb 02, 2002
Walter
Feb 02, 2002
Pavel Minayev
Feb 02, 2002
Walter
Feb 02, 2002
Pavel Minayev
Feb 02, 2002
Walter
Feb 02, 2002
Pavel Minayev
Feb 03, 2002
Paul Apostolik
Feb 03, 2002
Mike Wynn
Feb 03, 2002
Pavel Minayev
Feb 04, 2002
Russ Lewis
Feb 04, 2002
Pavel Minayev
Feb 04, 2002
Russ Lewis
Feb 04, 2002
Pavel Minayev
Feb 04, 2002
Russ Lewis
Feb 04, 2002
OddesE
Feb 03, 2002
Patrick Down
Mar 30, 2003
Russ Lewis
Mar 30, 2003
Matthew Wilson
February 02, 2002
How do I resolve the conflict of two interfaces in D. I wrote this:

    interface foo
    {
     void baz();
    }

    interface bar
    {
     void baz()
    }

    class foobar: foo, bar
    {
     void baz() { }
    }

Now foobar is supposed to have two versions of baz() - one from foo,
one from bar. But how do I implement them separately? I can just
write "void baz()", and the compiler doesn't complain (why?!), but
which method actually gets implemented? I tried foo.baz and bar.baz,
but it doesn't work...



February 02, 2002
One more thing. How to crash the compiler? Easy: =)

    class foobar: foobar.foo, foobar.bar
    {
     interface foo
     {
      void baz();
     }

     interface bar
     {
      void baz();
     }

     void baz() { }
    }

I don't see anything wrong in this code. Interfaces declared inside the class don't differ from those outside, it should be pretty legal to inherit that class from them... this can be useful if you want to deal with interfaces but don't want to expose them to others.

Also, when doing "class foobar: foo, bar", it complains that "identifier foo is not defined". Why? Shouldn't class know about all its members?



February 02, 2002
This works:

    interface foobar: foo, bar { }

This crashes the compiler:

    interface foobar: foo, bar;

Not to mention it definitely shoudln't, I think it should be a legal declaration, useful to "group" methods together or to declare a separate interface which doesn't differ from the base one (would be useful for COM event handling).


February 02, 2002
"Pavel Minayev" <evilone@omen.ru> wrote in message news:a3g93h$1944$1@digitaldaemon.com...
> How do I resolve the conflict of two interfaces in D. I wrote this:
>
>     interface foo
>     {
>      void baz();
>     }
>
>     interface bar
>     {
>      void baz()
>     }
>
>     class foobar: foo, bar
>     {
>      void baz() { }
>     }
>
> Now foobar is supposed to have two versions of baz() - one from foo,
> one from bar. But how do I implement them separately? I can just
> write "void baz()", and the compiler doesn't complain (why?!), but
> which method actually gets implemented? I tried foo.baz and bar.baz,
> but it doesn't work...

What happens is foobar.baz() becomes the baz implementation for BOTH foo and
bar.


February 02, 2002
"Pavel Minayev" <evilone@omen.ru> wrote in message news:a3g9c6$195r$1@digitaldaemon.com...
> One more thing. How to crash the compiler? Easy: =)
>
>     class foobar: foobar.foo, foobar.bar
>     {
>      interface foo
>      {
>       void baz();
>      }
>
>      interface bar
>      {
>       void baz();
>      }
>
>      void baz() { }
>     }
>
> I don't see anything wrong in this code. Interfaces declared inside the class don't differ from those outside, it should be pretty legal to inherit that class from them... this can be useful if you want to deal with interfaces but don't want to expose them to others.

It doesn't work because the compiler's name resolution hasn't parsed the inside of the class when it is trying to resolve the outside.

> Also, when doing "class foobar: foo, bar", it complains that "identifier foo is not defined". Why? Shouldn't class know about all its members?
>
>
>


February 02, 2002
"Walter" <walter@digitalmars.com> wrote in message news:a3gbov$1got$3@digitaldaemon.com...

> What happens is foobar.baz() becomes the baz implementation for BOTH foo
and
> bar.

And if I need to provide separate implementations?...


February 02, 2002
"Walter" <walter@digitalmars.com> wrote in message news:a3gbp0$1got$4@digitaldaemon.com...

> It doesn't work because the compiler's name resolution hasn't parsed the inside of the class when it is trying to resolve the outside.

So it should give an error message? 'cause it doesn't...


February 02, 2002
"Pavel Minayev" <evilone@omen.ru> wrote in message news:a3gfjr$1jb0$1@digitaldaemon.com...
> "Walter" <walter@digitalmars.com> wrote in message news:a3gbov$1got$3@digitaldaemon.com...
>
> > What happens is foobar.baz() becomes the baz implementation for BOTH foo
> and
> > bar.
>
> And if I need to provide separate implementations?...

Your only option is to change the name on one of the interfaces.


February 02, 2002
"Walter" <walter@digitalmars.com> wrote in message news:a3gh3a$1k44$2@digitaldaemon.com...

> Your only option is to change the name on one of the interfaces.

Aren't you going to add some way to resolve this, like in C# or Delphi? Like this:

    class foobar: foo, bar
    {
        void foo.baz() { ... }
        void bar.baz() { ... }
    }


February 02, 2002
"Pavel Minayev" <evilone@omen.ru> wrote in message news:a3gm8e$1m2f$1@digitaldaemon.com...
> "Walter" <walter@digitalmars.com> wrote in message news:a3gh3a$1k44$2@digitaldaemon.com...
> > Your only option is to change the name on one of the interfaces.
> Aren't you going to add some way to resolve this, like in C# or Delphi? Like this:
>
>     class foobar: foo, bar
>     {
>         void foo.baz() { ... }
>         void bar.baz() { ... }
>     }

I didn't know those languages offered that. While it's possible to implement that, is it really necessary to support it?


« First   ‹ Prev
1 2 3