943,552 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Marked Solved
  • Views: 991
  • C++ RSS
Oct 9th, 2008
0

Accessing a list of Pointer

Expand Post »
Hi ,

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

C++ Syntax (Toggle Plain Text)
  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..

C++ Syntax (Toggle Plain Text)
  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. }
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Kamal_Java is offline Offline
14 posts
since Sep 2008
Oct 9th, 2008
0

Re: Accessing a list of Pointer

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;
Sponsor
Team Colleague
Featured Poster
Reputation Points: 5608
Solved Threads: 2282
Retired and Enjoying Life
Ancient Dragon is offline Offline
21,947 posts
since Aug 2005
Oct 9th, 2008
0

Re: Accessing a list of Pointer

yup! No doubt .. It will crash ..As ancient dragon said u have to put
Quote ...
ebase = *iter
Reputation Points: 11
Solved Threads: 5
Newbie Poster
Aashath is offline Offline
18 posts
since Dec 2007

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Infininate loop
Next Thread in C++ Forum Timeline: abit of help needed help..ty





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC