for 循环后面多了个分号引发的灾难

struct ChatMsg
{
    ChatMsg()
    {
        memset(pstrChat, 0, sizeof(pstrChat));
        fromUserId = 0;
        specialFlag = 0;
        timestamp = 0;
    }
    char  pstrChat[256];
    DWORD fromUserId;            // 发起方
    BYTE specialFlag;
    DWORD timestamp;
    DWORD status;               //大于0已读小于等于0未读
};

class Relation
{
public:
    Relation()
    {
        id = 0;
        chatMsgs.clear();
    }
    ~Relation()
    {
        std::vector<ChatMsg*>::iterator iter = chatMsgs.begin();
        for (; iter != chatMsgs.end(); )
        {
            iter = chatMsgs.erase(iter);
        }
    }
    QWORD id;
    std::vector<ChatMsg*> chatMsgs;
};
int main()
{
    Relation* relation = new Relation();
    if (relation->chatMsgs.size() <= 0)
    {
        //return 0;
        std::cout << relation->chatMsgs.size()<<std::endl;
    }

    DWORD chatNum = 0;
    std::vector<ChatMsg*>::iterator chatIter = relation->chatMsgs.begin();
    for (; chatIter != relation->chatMsgs.end(); chatIter++)
    {
        ChatMsg* pMsg = *chatIter;
        if (pMsg && pMsg->status <= 0)
        {
            ++chatNum;
        }
    }

    while (1);
    return 0;
}

猜你喜欢

转载自blog.csdn.net/boshuzhang/article/details/88640121
今日推荐