[Vala] Boxed type generics



Hello,

I'd like to do something like the following (somewhat oversimplified):

public T increment<T> (T number) {
        return (double?) number + 1;
}
public static void main () {
        stdout.printf("%f\n", increment<double?> (4.7));
}

Unfortunately the C-compiler complains about not being able to convert
the double to a pointer type in the return statement.
I have found out this works as expected:

public T increment<T> (T number) {
        double tmp = (double?) number;
        tmp += 1;
        return &tmp;
}

This, however, seems not to be the right thing to do. Could someone
explain how to handle those boxed types correctly without resorting to
the address-of-operator?

Thanks,

Stephan




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]