Re: [Vala] Generic type argument



Hi again,

I've digged a bit further on my problem. Compiling the vala code to C
code, showed a temporary variable which was a float. Changing this
variable to a double fixes the problem of the 'random' value. I've
attached a minimal sample vala program, and diff to change the
resulting c code. (all with vala 0.7.5)

This still leaves me wondering why i need to box a double to use it as
a generic type, while an int can be used just like that.

Kind regards,
Thomas Meire

On Fri, Aug 7, 2009 at 8:53 PM, Thomas Meire<blackskad gmail com> wrote:
Hi all,

I tried to store a double in a Gee.Map for some algorithms I'm
writing, but the program failed to compile (with valac errors). After
reading a bit in the tutorial[1] and the reference draft[2], I decided
to try the example in the reference manual[3]. However, the program
failed to compile with the same error I had in my algorithms:

"error: `double' is not a supported generic type argument, use `?' to
box value types"

So I changed that line a bit to look like:

var t = new Two < int, double? > ();

With that line, it compiles (with some warnings), but the output is
not correct. It outputs some 'random' value instead of 5.
So what can i do to make the program compile and make it do what it's
supposed to do?

Thanks a lot,
Thomas

[1] http://live.gnome.org/Vala/Tutorial
[2] http://www.vala-project.org/doc/vala-draft/
[3] http://www.vala-project.org/doc/vala-draft/generics.html#genericsexamples

Attachment: test.vala
Description: Text Data

Attachment: test.diff
Description: Text Data



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