Cumulative

Steve Teale steve.teale at britseyeview.com
Fri Mar 7 01:17:28 PST 2014


On Friday, 7 March 2014 at 02:15:44 UTC, Nick Sabalausky wrote:
> On 3/6/2014 11:48 AM, Steve Teale wrote:

I can get tantalizingly close to what I want using the extra 
constructor argument.

In the base class I define a template function:

string initString(T)()
{
    return "string sname = 
\""~T.stringof~"\"~to!string(++nextOid);"
    "HandlerDelegates[] ahdg = [ HandlerDelegates( &"~
    T.stringof~".notifyHandler, &"~T.stringof~".undoHandler)];";
}

Then in the leaf class constructor I can just do:

mixin(initString!Arrow());
super(aw, parent, sname, AC_ARROW, ACGroups.SHAPES, ahdg);

Sadly the compiler does not complain if I comment out the leaf 
notifyHandler()
method, cos its virtual, and there's one in its parent class.

Does contract programming to provide a way to say that some 
function definition is required?

This is where I'd like to be able to say:

class Base
{
    // Method is called directly, but unlike a final
    // method it can be overidden in a derived class.
    direct bool notifyHandler(...) { ... }
}

class Inter
{
    // Kill the warning about hiding the base class method with 
override
    override bool notifyHandler(...) { ... }
}

As a side benefit, I think that mixing in a string generated by a 
template function gives me a way of generating something 
approximating a mixin template that allows more than just 
declarations - insertion of parameterized code at compile time ;=)

Steve


More information about the Digitalmars-d mailing list