Re: [libxml++] NodeList problem.
- From: Jonathan Wakely <cow compsoc man ac uk>
- To: Darko Miletic <darko uvcms com>
- Cc: libxmlplusplus-general lists sourceforge net
- Subject: Re: [libxml++] NodeList problem.
- Date: Thu, 9 Jun 2005 18:29:24 +0100
On Thu, Jun 09, 2005 at 01:53:03PM -0300, Darko Miletic wrote:
> Jonathan Wakely wrote:
>
> >Surely not?!?!
> >
> >If the container is empty calling begin() will return an iterator that
> >compares equal to end(). _dereferencing_ that iterator would be an
> >error, but not simply copying it.
>
> It will be error if you use (as you did) reference to NodeList. You
> wrote the code like this:
>
> const xmlpp::Node::NodeList& m_nodeList = root->get_children();
>
> that means that you take reference to the temporary created nodelist
> object. It is invalid after that line is executed an hence the access
Not true, the standard requires that a temporary object bound to a const
reference is kept in scope as long as the reference.
> violation. Therefore you need to copy it. Instead of const
> xmlpp::Node::NodeList& use just xmlpp::Node::NodeList that way the list
> will be copied as it should because the declaration of
> xmlpp::Node::get_children is like this:
>
> NodeList get_children(const std::string& name = std::string());
>
> So no reference is returned here.
>
> The code should be like this:
>
> xmlpp::Node::NodeList m_nodeList = root->get_children();
> xmlpp::Node::NodeList::const_iterator itr = m_nodeList.begin();
Not true, the original code should work AFAICT.
jon
--
"An alcoholic is someone you don't like who drinks as much as you do."
- Dylan Thomas
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]