Thread: Dereferencing Class Pointer List

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    I don't want you to add the type and compile it. I want you to do it in your head or on paper or in a scratch text file to understand what is happening.

    Also, it would help to know which line the problem is exactly. We'll try this line:
    Code:
    while( *it != mynewList->GetList()->end())
    mynewList->GetList() returns a medList * and calling end() on that will return a list<_medContainer>::iterator (ignore const for the moment). So the expressions is:
    Code:
    *it != list<_medContainer>::iterator
    Now, it is a medList::iterator * and so changing out medList for list<_medContainer> you get:
    Code:
    *(list<_medContainer>::iterator *) != list<_medContainer>::iterator
    You're dereferencing a pointer, so the list<_medContainer>::iterator * becomes just a list<_medContainer>::iterator giving you:
    Code:
    list<_medContainer>::iterator != list<_medContainer>::iterator
    You're comparing two objects of type list<_medContainer>::iterator, so you're fine. That line is probably not the problem. If you understand what I just did, do it for the Results->push_back(&(**it)); code and see what type you are sending to push_back.

  2. #2
    Registered User
    Join Date
    May 2005
    Location
    Texas
    Posts
    103
    Thanks for the reply! Well here are my thoughts:
    Code:
    while( *it != mynewList->GetList()->end())
    	{					//EXPLANATION(S)
    		Results->push_back(&**it);      //*it = iterator which points to a Container
    					        //**it = (double dereference) Access the pointer that it pointer is pointing to
    						//&(**it) = the address of the object being pointed by two pointers
    
    		/*
    		//APPLICATION
    		Results -> push_back( --- takes a _medContainer* )
    		Therefore Results -> push_back( &(**it) ); is Plausible, isn't it?
    		*/
    					//EXPLANATION(S)
    					//Results->push_back( of type _medContainer* )
    					//(**it) = The object the iterator is pointing to, Hence &_medContainer
    					//So why the need for the extra ampersand(&)? 
    					//Perhaps to forward the Address of the object through the pointer?
    		*it++;
    	}
    however this
    Code:
    while( *it != mynewList->GetList()->end())
    appears to be the problem because once I filter out the rest of while loop(the pushback() and the *it++; ) it still crashes on me

    Anyone got ideas?
    Last edited by toonlover; 08-15-2008 at 03:07 AM.
    Be easy on me...only 14

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 03-22-2009, 05:03 AM
  2. template and friend class
    By black_spot1984 in forum C++ Programming
    Replies: 3
    Last Post: 10-21-2008, 05:50 PM
  3. Sorting linked list please help with CODE
    By scarlet00014 in forum C Programming
    Replies: 3
    Last Post: 09-27-2008, 11:24 PM
  4. Smart pointer class
    By Elysia in forum C++ Programming
    Replies: 63
    Last Post: 11-03-2007, 07:05 AM
  5. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 06-18-2002, 01:27 PM