• Advertisement
Sign in to follow this  

Accessing functionality inside boost::ptr_list

This topic is 2903 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, I am getting a little mixed up at the moment. I am trying to access the functions of a class object that is inside boost::ptr_list. That boost::ptr_list is held inside a different class object which is held inside a std::vector. So in short
// When the button is hovered
if( m_listboxes->GetID() == m_currentHoveredControl )
{
	// Tell it is hovered
	for ( unsigned int n = 0; n != m_listboxes->GetListItems().size(); n++ )
	{
		// I am try to access the certain listItem held inside a boost:ptr_list
		// Obviously this does not work but I am trying to figure out what I need to do. 
		//m_listboxes->GetListItems()[n].SetHovered( true );
	}
}



m_listboxes is a std::vector which holds a class object which holda a boost::ptr of "listItems". Regards Chad [Edited by - chadsxe on February 11, 2010 11:14:44 AM]

Share this post


Link to post
Share on other sites
Advertisement
A boost:ptr_list doesn't have random access, so you'll need to use iterators. Plus it might not be a bad idea to use some aliases here and there [smile] And typedef's, too, which I omitted:

ListBoxType* listBox = m_listboxes;
// ..
if(listBox->GetID() == m_currentHoveredControl)
{
boost::ptr_list<ItemType>& listItems = listBox->GetListItems();

for(boost::ptr_list<ItemType>::iterator it = listItems.begin(); it != listItems.end(); ++it)
{
it->SetHovered(true);
}
}

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement