D - abstract classes
- Martin M. Pedersen (38/38) Jul 25 2003 Hi,
- Dario (15/15) Jul 27 2003 Try:
- Martin M. Pedersen (4/19) Jul 28 2003 It doesn't work (with DMD 0.68): "class AbstractImpl interface function
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
Jul 25 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"); }
}
Jul 27 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"); }
}
Jul 28 2003








"Martin M. Pedersen" <martin moeller-pedersen.dk>