I’m just starting to learn Vala using the tutorial. Is it possible to call an interface’s method? Here are two snippets based on code from the tutorial, the first works:
// This works
public interface Callable : GLib.Object {
public abstract bool answering { get; protected set; }
public virtual bool hang ()
{
answering = false;
return true;
}
}
public class TechPhone : GLib.Object, Callable
{
public bool answering { get; protected set; }
public bool hang ()
{
stdout.printf ("TechPhone.hang () implementation!");
answering = false;
return true;
}
public static void main ()
{
var f = new TechPhone ();
if (f.hang ())
stdout.printf("Hand done.\n");
else
stdout.printf("Hand Error!\n");
stdout.printf("END\n");
}
}
But this code won’t compile:
// Doesn't work: note that Callable is the same as above so omitted
public class TechPhone : GLib.Object, Callable
{
public bool answering { get; protected set; }
public bool hang ()
{
stdout.printf ("TechPhone.hang () implementation!");
return Callable.hang();
}
public static void main ()
{
var f = new TechPhone ();
if (f.hang ())
stdout.printf("Hand done.\n");
else
stdout.printf("Hand Error!\n");
stdout.printf("END\n");
}
}
The error is:
test.vala:16.14-16.28: error: Access to instance member `Callable.hang' denied
return Callable.hang();
^^^^^^^^^^^^^^^
Compilation failed: 1 error(s), 0 warning(s)
PS I hope this is the right category: I couldn’t find one for ‘learn’ or ‘help’.