Hello Jason, Jason House ha escrito:
Below is a small piece of code that I can't get to compile. gcc says: error: forward declaration of 'class search_node'
Is there a way to get around this, or can I not embed a multi_index_container like that? I'm using boost 1_32_0 and gcc version 4.0.1
The code below is for a node within a search tree. Each node stores a
class search_node{ int objective_value; // Objective function position my_position; // Move location for this step in the search std::list<position> positions_to_visit; // Future moves to consider in search boost::multi_index_container < search_node, indexed_by< ordered_unique <search_node, position, &search_node::my_position>, ordered_non_unique<search_node, int, &search_node::objective_value> > > search_results; };
(First of all, you're missing the member<> part inside ordered_unique<...> and ordered_non_unique. I assume this is just a copy&paste error and that you're actually using member<>.) Unfortunately, multi_index_container cannot be instantiated for incomplete types, as you're doing by defining the type of search_results inside search_node itself. To escape this self-referentiality, you can add a level of indirection like this: boost::multi_index_container < const search_node*, indexed_by< ordered_unique <member<search_node, position, &search_node::my_position> >, ordered_non_unique<member<search_node, int, &search_node::objective_value> >
search_results;
or boost::multi_index_container < boost::reference_wrapper<const search_node>, indexed_by< ordered_unique <member<search_node, position, &search_node::my_position> >, ordered_non_unique<member<search_node, int, &search_node::objective_value> >
search_results;
both of which are appropriate if the life cycle of the elements referenced by search_results are properly managed outside search_results. If this is not the case, i.e. if search_results must take care of properly destroying the referenced search_node's, you can use: boost::multi_index_container < boost::shared_ptr<const search_node>, indexed_by< ordered_unique <member<search_node, position, &search_node::my_position> >, ordered_non_unique<member<search_node, int, &search_node::objective_value> >
search_results;
Hope this helps, Joaquín M López Muñoz Telefónica, Investigación y Desarrollo