# Polymorphism delete vector problem

**URL:** <https://community.unix.com/t/polymorphism-delete-vector-problem/298637>\
**Category:** Programming\
**Created:** [November 5, 2011, 11:22am UTC](https://community.unix.com/t/polymorphism-delete-vector-problem/298637 "2011-11-05T11:22:51Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![GQiang](https://community.unix.com/letter_avatar/gqiang/32/6_449c533f586939b6e5f246632a46421f.png) [@GQiang](https://community.unix.com/u/GQiang)\
**Post date:** [November 5, 2011, 11:22am UTC](https://community.unix.com/t/polymorphism-delete-vector-problem/298637/1 "2011-11-05T11:22:51Z")

</div>

Hi all

Really need some help here, i have a vector of pointer "vector\<\*e.g\>store" i need to delete one of the chosen container and it seem like the normal way of deleting a vector cannot work!

P.S new to polymorphism  
Thank

Here is a cut out of my codes

```nohighlight
for(unsigned i=0;i<store.size();i++){
            temp=store->getID();
            if(temp==input){
                //here should be the deleting vector code but i having problem
            }
        } 

```

---

<div class="post-metadata">

**Author:** ![GQiang](https://community.unix.com/letter_avatar/gqiang/32/6_449c533f586939b6e5f246632a46421f.png) [@GQiang](https://community.unix.com/u/GQiang)\
**Post date:** [November 7, 2011, 7:08am UTC](https://community.unix.com/t/polymorphism-delete-vector-problem/298637/2 "2011-11-07T07:08:04Z")

</div>

I have solve my problem!!

```nohighlight
       
for(unsigned i=0;i<store.size();i++){
            temp=store->getID();
            if(temp==input){
                delete store;//free the memory to prevent memory leak
                store.erase(store.begin()+i);//prevent dangling point
                throw(4);
            }
        } 

```
