java—如何正确地将对象添加到数组中(处理3.5.4)

0lvr5msh  于 2021-06-29  发布在  Java
关注(0)|答案(1)|浏览(300)

目前我有:

nameHere[] array;
void setup() {
 array = new nameHere[60];
}

void draw() {
 //statements go here
}

class nameHere {
 int nameA, nameB, nameC;
 nameHere (int a, int b, int c) {
  nameA = a;
  nameB = b;
  nameC = c;
 }
 void functionHere() {
  //statements go here
 }
}

void mousePressed() {
 array.append(nameHere(0, 0, 0));
}

据我所知,我所有的语法都是正确的。控制台返回的错误是“function namehere(int,int,int)不存在”。有人能解释一下吗?

w1e3prcc

w1e3prcc1#

我认为,正如你所说的那样,错误是在行的

array.append(nameHere(0, 0, 0))

您缺少关键字new before namehere(0,0,0),这会导致编译器认为您要调用一个不存在的函数。通过添加关键字,您告诉编译器应该在此处创建类名的示例。
不幸的是,我不能测试的解决方案,但希望它有帮助!

相关问题