我的一个list要做push_back操作,可是push_back没反应?大家帮我看看。急!解决了再加100.typedef struct TagContactItem
{
    int iID;}TagContactItem;

typedef std::list<TagContactItem> TagContactItems; TagContactItems  aTagContactItems;void fun(TagContactItems&  aTagContactItems)
{
    TagContactItem stContactItem;
    for(int i = 0 ; i < 5; i++)
    {
        stContactItem.iID = i;
        ::MessageBox(NULL,"1","1",1);
        aTagContactItems.push_back(stContactItem);//这句没响应,运行到这就没了。
        ::MessageBox(NULL,"2","2",1);
    }}

解决方案 »

  1.   

    总的是这样的:.h 文件的代码:
    typedef struct TagContactItem
    {
        int iID;}TagContactItem;
        
    typedef std::list<TagContactItem> TagContactItemspublic: 
        TagContactItems m_ContactItems; 
        void FillContactItems(TagContactItems& aTagContactItems);.cpp 文件的代码:
    void main()
    {
        fun(this->ContactItems);
    }
    void fun(TagContactItems&  aTagContactItems)
    {
        TagContactItem stContactItem;
        for(int i = 0 ; i < 5; i++)
        {
            stContactItem.iID = i;
            ::MessageBox(NULL,"1","1",1);
            aTagContactItems.push_back(stContactItem);//这句没响应,运行到这就没了。
            ::MessageBox(NULL,"2","2",1);
        }}
      

  2.   

    我使用你的代码测试了一下,没有问题啊,
    不过,如果list保存的是类对象不是很好,那样需要实现深拷贝。
    建议保存指针。
    typedef std::list<TagContactItem> TagContactItems; 
    变更为
    typedef std::list<TagContactItem*> TagContactItems; 
      

  3.   

    没有封装到DLL里吧,如果封装到DLL,这样调用就肯定出事
      

  4.   

    void main()
    {
        fun(this->ContactItems);
    }this指针哪里的。
      

  5.   

    我觉得push_back应该不会出现不返回的现象。
    LZ的代码我也进行了测试,可以正常运行。
      

  6.   

    建议保存指针.保存 pstContactItem ,动态生成空间. 
    因为现在这样可能会涉及到深拷贝的问题, 所以改成指针的方式来维护试试.
      

  7.   


    运行到push_back,就停止了!
      

  8.   

    Quote=引用 8 楼 blueink_200451 的回复:]
    学习中。给顶一下。
    [/Quote]
      

  9.   

    这个的:
    TagContactItems m_ContactItems; this->m_ContactItems;
      

  10.   

    恩,都搞定了,呵呵,遇到野指针了。谢谢大家哈!谢谢 flight_lcf !