abstract function templates

Nrgyzer nrgyzer at gmail.com
Sun Dec 26 23:40:10 PST 2010


The sense is that I have different, drawable classes/object - for
example a simple texture (not clickable) and a button (clickable).
When the user clicks the mouse, the obj-param which is defined by
using draw!(T = void*)(uint zPos, T obj = null) will be saved in a
template-struct which should have the type of obj -> struct myStruct
(T). The advantage is, that I can use the obj referenced in the
struct without any casting.

I just solved the problem by declaring draw() as final-function and
used a new value as callback in the final draw()-function - for
example:

...
private void delegate() drawCallback;

public final void draw(T = void*)(uint zPos, T obj = null) {

	drawCallback();

	// ... do additional work
}


More information about the Digitalmars-d-learn mailing list