Accessing a list of Pointer

Please support our C++ advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Sep 2008
Posts: 11
Reputation: Kamal_Java is an unknown quantity at this point 
Solved Threads: 0
Kamal_Java Kamal_Java is offline Offline
Newbie Poster

Accessing a list of Pointer

 
0
  #1
Oct 9th, 2008
Hi ,

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

  1. 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..

  1. list<BaseClass*>::const_iterator iter = eBList.begin( );
  2.  
  3. BaseClass *ebase
  4.  
  5. for( ; iter != eBList.end( ); iter++ )
  6. {
  7. if( typeid( **iter ) == typeid( DerivedClass ) )
  8. {
  9. *ebase = **iter; ///// CRASHES HERE .. how do i assign to this variable
  10. break;
  11. }
  12.  
  13.  
  14. }
Reply With Quote Quick reply to this message  
Join Date: Aug 2005
Posts: 15,348
Reputation: Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute Ancient Dragon has a reputation beyond repute 
Solved Threads: 1461
Team Colleague
Featured Poster
Ancient Dragon's Avatar
Ancient Dragon Ancient Dragon is offline Offline
Still Learning

Re: Accessing a list of Pointer

 
0
  #2
Oct 9th, 2008
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;
Don't PM me with questions -- you might get a nasty PM in response. If you have a question then post it in one of the forums.
Reply With Quote Quick reply to this message  
Join Date: Dec 2007
Posts: 18
Reputation: Aashath is an unknown quantity at this point 
Solved Threads: 5
Aashath's Avatar
Aashath Aashath is offline Offline
Newbie Poster

Re: Accessing a list of Pointer

 
0
  #3
Oct 9th, 2008
yup! No doubt .. It will crash ..As ancient dragon said u have to put
ebase = *iter
"The most important single aspect of software development is to be clear about what you are trying to build." - Bjarne Stroustrup
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC