1

我刚从 Vala 开始,我尝试制作一个简单的程序来询问两个输入:

  1. 指定循环度的 int;和
  2. 一个包含用于迭代或递归过程的 I/R 的字符。

就在编译之前,我收到了这个错误:

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)

非常简单的程序的 pastebin 位于此处

这是一个片段:

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
}

您能告诉我该怎么做,以及一些提示吗?谢谢。

4

1 回答 1

2

您定义test_exec为实例(非静态)方法。与静态方法不同,需要在给定类的实例上调用实例方法。但是,您试图在没有这样的实例的情况下调用它,因此会出现错误。

所以你要么需要创建一个test0类的实例并调用test_exec它(尽管这没有什么意义,因为test_exec它不依赖或改变对象的任何状态 - 事实上test0类没有任何状态)或test_exec以及test_exec静态调用的其他方法。

于 2011-03-25T16:06:32.260 回答