我想在X ++中存储对象列表。我读过msdn中的数组和容器不能存储对象,所以唯一的选择是创建一个Collection的列表。我写了下面的代码,并尝试使用Collection = new List(Types::AnyType);
和Collection = new List(Types::Classes);
,但两者都不起作用。请看看我是否在以下工作中犯了一些错误。对象集合
static void TestList(Args _args)
{
List Collection;
ListIterator iter;
anytype iVar, sVar, oVar;
PlmSizeRange PlmSizeRange;
;
Collection = new List(Types::AnyType);
iVar = 1;
sVar = "abc";
oVar = PlmSizeRange;
Collection.addEnd(iVar);
Collection.addEnd(sVar);
Collection.addEnd(oVar);
iter = new ListIterator(Collection);
while (iter.more())
{
info(any2str(iter.value()));
iter.next();
}
}
此外,我们不能将一些变量或对象转换为Anytype变量,我读出类型转换自动完成这种方式;
anytype iVar;
iVar = 1;
但是在运行时抛出一个错误,期望类型是Anytype,但是遇到的类型是int。第一
评论#1 运行job2时得到此异常... 执行代码时出错:转换函数的参数类型错误。 堆栈跟踪 (C)\作业\作业2 - 线6 –
@BilalSaeed - 评出“的Ivar = 1”,并且将anytype类型被绑定到一个串和any2str将工作。 –
删除'any2str',它不适用于绑定到int的'anytype'! –