Some background: I'm currently learning vala by way of C#. Basically
I'm learning C# and "translating" what I learn to vala.
So I've come across delegates. From the C# book I'm reading they give
the example that looks basically like this:
MyDel del;
...
del = randValue < 50 ? new MyDel(program.PrintLow) : new
MyDel(program.PrintHigh);
Using the "Vala for C# Programmers"[1] guide I've translated this to:
MyDel del;
...
del = randValue > 50 ? program.PrintLow : program.PrintHigh;
However this gives me a compile error:
delegate.vala:21.32-21.47: error: Assignment: Cannot convert from
`Program.PrintLow' to `Program.PrintLow'
del = randValue < 50 ? program.PrintLow : program.PrintHigh;
^^^^^^^^^^^^^^^^
delegate.vala:21.51-21.67: error: Assignment: Cannot convert from
`Program.PrintHigh' to `Program.PrintHigh'
del = randValue < 50 ? program.PrintLow : program.PrintHigh;
^^^^^^^^^^^^^^^^^
delegate.vala:21.15-21.28: error: Incompatible expressions
del = randValue < 50 ? program.PrintLow : program.PrintHigh;
^^^^^^^^^^^^^^
Compilation failed: 3 error(s), 0 warning(s)
However a simple assignment works:
del = program.PrintLow;
So is the problem with the ternary expression? I also tried putting the
conditional expression in parens but that didn't make any difference.
Using Vala 0.18.1
[1] https://live.gnome.org/Vala/ValaForCSharpProgrammers
_______________________________________________
vala-list mailing list
[email protected]
https://mail.gnome.org/mailman/listinfo/vala-list