I have just started out in Vala, and I tried to make a simple program that asks two inputs:
- An int that specifies a cycle degree; and
- A char that contains I / R for either an iterative or recursive process.
Just before compiling, I got this error:
test0.vala:8.5-8.16: error: Access to instance member `test0.test_exec' denied
test_exec(q);
^^^^^^^^^^^ //the entire statement
Compilation failed: 1 error(s), 0 warning(s)
The pastebin for the very simple program is located here.
Here’s a snippet:
public static void main(string[] args)
{
stdout.printf("Greetings! How many cycles would you like? INPUT: ");
int q=0;
stdin.scanf("%d", out q);
test_exec(q);
}
public void test_exec(int q)
{
//method code here
}
Can you please enlighten me about what to do, and some tips? Thanks.
You defined
test_execas an instance (non-static) method. Unlike a static method, an instance method needs to be called on an instance of the given class. However you’re trying to call it without such an instance and thus get an error.So you either need to create an instance of the
test0class and calltest_execon that (though that would make little sense sincetest_execdoes not depend on or change any state of the object – as a matter of fact thetest0class does not have any state) or maketest_execas well as the other methods called bytest_execstatic.