0

Hi ,

I have a stl list which stores my base class pointer .Like

list<BaseClass*> eBList;

now i want to iterate through this list and store it in one local variable. how do i do this. i have shown below the code i tried .... But at one part it crashes..

list<BaseClass*>::const_iterator iter = eBList.begin( );

BaseClass *ebase

for( ; iter != eBList.end( ); iter++ )
    {
         if( typeid( **iter ) == typeid( DerivedClass ) )
         {
                   *ebase = **iter;    ///// CRASHES HERE    .. how do i assign to this variable      
                   break;     
           }
              
              
         }
3
Contributors
2
Replies
3
Views
8 Years
Discussion Span
Last Post by Aashath
0

First you have to allocate memory for ebase -- you are dereferencing an unallocated pointer. So the best you can do with that is ebase = *iter;

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.