本文介绍了Dart中的类对象操作列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
下面的代码块有问题.
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"成员.我在这里想念什么吗?
Not able to find "listEvents" member after GList constructor is called. Am I missing anything here.
引用 glist.listSVList [index]
->找不到成员变量'listEvents'.任何指针表示赞赏.
Referencing glist.listSVList[index]
--> do not find member variable 'listEvents'. Any pointers appreciated.
详细地说,找不到带有'glist.listSVList [index] .listEvents'的成员变量.
To elaborate , no member variable with 'glist.listSVList[index].listEvents' is found.
推荐答案
您在这里有错字:
this.listSVList = new List<SvList>(num); // <== SVList not SvList
功能
在这里似乎是错误的
function f1 () { ... }
在这种情况下,您使用 function
作为返回类型
in this case you use function
as a return type
另一种错字:
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会立即显示所有错误.
What editor are you using?
DartEditor showed all errors immediately after I pasted your code.
这篇关于Dart中的类对象操作列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!