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;     
           }
              
              
         }

Recommended Answers

All 2 Replies

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;

yup! No doubt .. It will crash ..As ancient dragon said u have to put

ebase = *iter

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.