super constructors: I can't take it anymore!
Serg Kovrov
kovrov at no.spam
Wed Aug 16 06:43:16 PDT 2006
* Regan Heath:
> import std.stdio;
>
> typedef int function(int i) WNDPROC;
>
> class BaseWindow
> {
> void register(char[] cname) { writefln("register(",cname,")"); }
> void create(int function(int) f) { writefln("create(",f(1),")"); }
>
> char[] classname() { return "BaseWindow"; }
> WNDPROC windproc() { return cast(WNDPROC)function int(int i){return
> i;}; }
>
> this() { register(classname()); create(windproc()); }
> }
>
> class FrameWindow : BaseWindow
> {
> override char[] classname() { return "FrameWindow"; }
> override WNDPROC windproc() { return cast(WNDPROC)function int(int
> i){return i*2;}; }
> }
>
> void main()
> {
> FrameWindow b = new FrameWindow();
> BaseWindow a = new BaseWindow();
> }
Thank you, Regan.
This is pretty good looking solution. Seems all solutions are about to
avoid using constructors in subclasses at all.
Sadly, constructors appears to be weak in D. I wish some day it will be
changed.
--
serg.
More information about the Digitalmars-d-learn
mailing list