开发者

What does this error in calling a method mean?

I have just started out in Vala, and I tried to make a simple program that asks two inputs:

  1. An int that specifies a cycle degree; and
  2. 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开发者_JAVA技巧 tips? Thanks.


You defined test_exec as 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 test0 class and call test_exec on that (though that would make little sense since test_exec does not depend on or change any state of the object - as a matter of fact the test0 class does not have any state) or make test_exec as well as the other methods called by test_exec static.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜