迭代指针列表

时间:2016-03-11 12:31:00

标签: c++ list pointers

我正在尝试使用以下代码迭代Window对象指针列表:

    auto windowPtr = reinterpret_cast<std::list<Window>*>(lParam);

    for (std::list<Window*>::const_iterator it = windowPtr.begin(); it != windowPtr.end(); ++it)
    {
        if ((*it)->handle == hwnd)
        {
            state = true;
        }
    }

但是我收到错误标记windowPtr.begin()windowPtr.end()说:

std::list<Window> *windowPtr   Error: expression must have class type

我在这里做错了什么?

1 个答案:

答案 0 :(得分:0)

你正在寻找这样的东西吗?

    <Panel>
        <content>
            <Button class="btn editTable"></Button>
        </content>
    </Panel>
    <Table id="Listing" class="tableList" mode="MultiSelect" items="{path: 'masterData>/contactsList'}">
        <columns>
            <Column minScreenWidth="Tablet" demandPopin="true">
                <Text text="{i18n>vendorNum}"/>
            </Column>
            <Column minScreenWidth="Tablet" demandPopin="true">
                <Text text="{i18n>recipientType}"/>
            </Column>
            <Column minScreenWidth="Tablet" demandPopin="true">
                <Text text="{i18n>eMail}"/>
            </Column>
        </columns>

        <items>
            <ColumnListItem>
                <cells>
                    <Text text="{masterData>vendorNum}"/>
                </cells>
                <cells>
                    <Text text="{masterData>recipientType}"/>
                </cells>
                <cells>
                    <Text text="{masterData>eMail}"/>
                </cells>
            </ColumnListItem>
        </items>
    </Table>

或者您可以使用某些标准函数

BOOL CALLBACK EnumWindowsProc(HWND hwnd, LPARAM lParam)
{
    std::list<Window*>* windows = reinterpret_cast<std::list<Window*>>(lParam);
    bool state = false;
    for (std::list<Window*>::const_iterator it = windowPtr->begin(); it != windowPtr->end(); ++it)
    {
        if ((*it)->handle == hwnd)
        {
            state = true;
        }
    }
    return TRUE;
}

int main(int argc, char** argv)
{
     std::list<Window*> windows;

     ...

     EnumWindows(EnumWindowsProc, (LPARAM)&windows);
}