【发布时间】:2012-05-24 07:41:30
【问题描述】:
我正在将科学代码从 Java 迁移到 C++。请告诉我:
a) 这两个函数有什么问题?
b) 我该如何解决这个问题?我可以像使用二维数组一样使用int**,但不能使用Agent**。
我收到此错误:“没有运算符 = 匹配此操作数”。
在普通的 C 语言中,我们可以将 NULL 分配给指针。我们也可以像二维数组一样使用type**(即a[i][j])(objectSpace 和agentSpace 的二维空间分配在其他地方)。
int** objectSpace;
Agent** agentSpace;
void Space::removeAgentAt(Point p)
{
agentSpace[p.x][p.y] = NULL;
}
void Space::putAgentTo(Agent agent, Point p)
{
agentSpace[p.x][p.y] = agent;
}
【问题讨论】:
标签: c++ arrays object pointers