我有这个 [不完整] 功能:
void EditorWindow::OnLMClick(SObjectType sOT, short xPos, short yPos)
{
SObject* pSObject;
int nElements;
switch(sOT)
{
case SOT_Tile: nElements=TILETYPE_COUNT; pSObject = pSOTile[0]; break;
case SOT_Surface: nElements=SURFACEBMP_COUNT; break;
case SOT_Object: nElements=OBJECTBMP_COUNT; break;
case SOT_Edit: nElements=EDITBMP_COUNT; break;
default: MessageBox(NULL,"Switch does not include this SObjectType","Error in EditorWindow::OnLMClick()",NULL); return;
}
// From there on, pSObject may be pointing to any array of its child classes
for (int n = 0; n<nElements; n++)
{
if (xPos > pSObject->coor.X &&
xPos < pSObject->coor.X + pSObject->size.Width &&
yPos > pSObject->coor.Y &&
yPos < pSObject->coor.Y + pSObject->size.Height)
{
selectedItemRect.left = pSObject->coor.X;
selectedItemRect.top = pSObject->coor.Y + pSObject->size.Width;
selectedItemRect.right = pSObject->coor.X;
selectedItemRect.bottom = pSObject->coor.Y + pSObject->size.Height;
}
*(pSObject++);
}
Display();
}
我试图让 pSObject 指向数组 pSOTile 的下一个元素。我怎样才能做到这一点?请注意,由于我将更新函数,pSObject 最终将有可能指向其他子对象,而不仅仅是 SOTile。