[Vala] Boxed type generics
- From: Stephan Hilb <stephan ecshi net>
- To: vala-list gnome org
- Subject: [Vala] Boxed type generics
- Date: Mon, 19 Mar 2012 13:59:33 +0100
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]