在下面的代码块中有问题。
class Events
{
// some member variables
}
class SVList
{
String name;
int contentLen;
List<Events> listEvents;
SVList()
{
this.name = "";
this.contentLen = 0;
this.listEvents = new List<Events>();
}
}
class GList
{
List<SVList> listSVList;
GList(int Num)
{
this.listSVList = new List<SvList>(num);
}
}
function f1 ()
{
//array of class objects
GList gList = new GList(num);
}
调用 GList 构造函数后无法找到“listEvents”成员。我在这里有什么遗漏吗。
引用
glist.listSVList[index]
--> 找不到成员变量“listEvents”。任何指针表示赞赏。详细地说,没有找到带有 'glist.listSVList[index].listEvents' 的成员变量。
最佳答案
你这里有一个错字:
this.listSVList = new List<SvList>(num); // <== SVList not SvList
function
这里似乎错了function f1 () { ... }
在这种情况下,您使用
function
作为返回类型另一个错字:
GList(int Num) // <== Num (uppercase)
{
this.listSVList = new List<SvList>(num); // <== num (lowercase)
}
此代码有效:
class Events {
// some member variables
}
class SVList {
String name;
int contentLen;
List<Events> listEvents;
SVList() {
this.name = "";
this.contentLen = 0;
this.listEvents = new List<Events>();
}
}
class GList {
List<SVList> listSVList;
GList(int num) {
this.listSVList = new List<SVList>(num);
}
}
main() {
//array of class objects
GList gList = new GList(5);
gList.listSVList[0] = new SVList();
gList.listSVList[0].listEvents.add(new Events());
print(gList.listSVList[0].listEvents.length);
}
你用的是什么编辑器?
我粘贴代码后,DartEditor 立即显示所有错误。
关于dart - Dart 中的类对象操作列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23779679/