This is essentially what I'm trying to accomplish. The intuitive solution, of course, does not work. In theory I could write a separate method for every anticipated return type, but that would be horrible and in that case I'd probably just write the damn thing in a dynamically-typed language instead.

    import std.conv;

    abstract class BaseClass{
        abstract X convertSomePropertyTo(X)();
    }

    class SubClass(T): BaseClass{
        T property;
        X convertSomePropertyTo(X)(){
            return property.to!X;
        }
    }

    void main(){
        BaseClass obj = new SubClass!int;
auto x = obj.convertSomePropertyTo!real; // Error: function test.BaseClass.convertSomePropertyTo!real.convertSomePropertyTo non-virtual functions cannot be abstract
    }

Reply via email to