Thread overview
abstract classes
Jul 25, 2003
Martin M. Pedersen
Jul 27, 2003
Dario
Jul 28, 2003
Martin M. Pedersen
July 25, 2003
Hi,

I'm trying to implement a template pattern, but I have problems making it compile. What I want to do, is something like this:

============================
interface SomeInterface {
    void a();
    void b();
}

class AbstractImpl: SomeInterface {
    void b() { a(); }
}

class Foo: AbstractImpl {
    void a() { printf("foo\n"); }
}

class Bar: AbstractImpl {
    void a() { printf("bar\n"); }
}
============================

But the compiler complains: "class AbstractImpl interface function SomeInterface.a is not implemented". Of cause it isn't implemented - it wasn't intended to - it was intended to be abstract. Then I try to AbstractImpl as:

    abstract class AbstractImpl: SomeInterface { ...

then I get: "function b abstract function cannot have bodies". Maybe "abstract" on class level applies to all methods in the class? If this is the case, it is useless, as we have "interface". Then I try to apply "abstract" to AbstractImpl.a by declaring:

    class AbstractImpl: SomeInterface {
        abstract void a();
        void b() { ...

Now I get the first error message again: "class AbstractImpl interface function SomeInterface.a is not implemented".


How does one write this?

Is it documented? "abstract" is not documented in http://www.digitalmars.com/d/attributes.html exect that the attribute exists, and cannot find it elsewhere.


Regards,
Martin M. Pedersen


July 27, 2003
Try:

interface SomeInterface {
void a();
void b();
}
class AbstractImpl: SomeInterface {
abstract void a();
void b() { a(); }
}
class Foo: AbstractImpl {
void a() { printf("foo\n"); }
}
class Bar: AbstractImpl {
void a() { printf("bar\n"); }
}


July 28, 2003
It doesn't work (with DMD 0.68): "class AbstractImpl interface function SomeInterface.a is not implemented"

"Dario" <Dario_member@pathlink.com> wrote in message news:bg0sgk$2l01$1@digitaldaemon.com...
> Try:
>
> interface SomeInterface {
> void a();
> void b();
> }
> class AbstractImpl: SomeInterface {
> abstract void a();
> void b() { a(); }
> }
> class Foo: AbstractImpl {
> void a() { printf("foo\n"); }
> }
> class Bar: AbstractImpl {
> void a() { printf("bar\n"); }
> }
>
>