overloaded const/non-const functions and bind

Hi, I want to use a function in bind that has a const and non-const version named Node::get_parent. I am using the following expression: NodeSet nodes_whitespace = doc->get_root_node()->find("//text()[normalize-space()='']"); for_each(nodes_whitespace.begin(), nodes_whitespace.end(), bind(&Node::remove_child, bind(&Node::get_parent, _1))); I get the obvious error: ../parsers-refact/trans-full/main.cpp: In function ‘void remove_whitespace_nodes(xmlpp::Document*)’: ../parsers-refact/trans-full/main.cpp:56: error: call of overloaded ‘bind(<unresolved overloaded function type>, boost::arg<1>&)’ is ambiguous /usr/local/include/boost/bind/bind_mf_cc.hpp:20: note: candidates are: boost::_bi::bind_t<R, boost::_mfi::mf0<R, T>, typename boost::_bi::list_av_1<A1>::type> boost::bind(R (T::*)(), A1) [with R = xmlpp::Element*, T = xmlpp::Node, A1 = boost::arg<1>] /usr/local/include/boost/bind/bind_mf_cc.hpp:30: note: boost::_bi::bind_t<R, boost::_mfi::cmf0<R, T>, typename boost::_bi::list_av_1<A1>::type> boost::bind(R (T::*)()const, A1) [with R = const xmlpp::Element*, T = xmlpp::Node, A1 = boost::arg<1>] Is there a way to get the const_iterator? Or is there any other solution? Thank you, Andrej

Hi Igor, Thanks for your reply.
You have to cast &Node::get_parent explicitly to one of the available overloads, to resolve ambiguity.
Any pointers on how to do this? My compiler keeps complaining. This is how I cast: NodeSet nodes_whitespace = doc->get_root_node()->find("//text()[normalize-space()='']"); for_each(nodes_whitespace.begin(), nodes_whitespace.end(), bind(&Node::remove_child, bind(static_cast<Node*(Node::*)()>(&Node::get_parent), _1))); This is what my compiler thinks about it: main.cpp: In function ‘void remove_whitespace_nodes(xmlpp::Document*)’: main.cpp:58: error: invalid static_cast from type ‘<unresolved overloaded function type>’ to type ‘xmlpp::Node* (xmlpp::Node::*)()’ How should I do this then? Thank you, Andrej

Hi, Sorry for the spam, the member function type was incorrect, the return type was Element* and not Node*. Thank you, Andrej
participants (2)
-
Andrej van der Zee
-
Igor R