deque iterator problem with const

F

Frederik Himpe

I'm implementing a SAX handler with libxml++. I have this piece of code:

void PalamedeParser::eek:n_start_element(const std::string &name, const
AttributeList &attributes) {
AttributeList::iterator it = attributes.begin();

with AttributeList defined as
typedef std::deque< Attribute > xmlpp::SaxParser::AttributeList

On the initialization of the iterator, I got this error:

conversion from
`__gnu_norm::_Deque_iterator<xmlpp::SaxParser::Attribute, const
xmlpp::SaxParser::Attribute&, const xmlpp::SaxParser::Attribute*>' to
non-scalar type `__gnu_norm::_Deque_iterator<xmlpp::SaxParser::Attribute,
xmlpp::SaxParser::Attribute&, xmlpp::SaxParser::Attribute*>' requested

It seems the compiler does not like the fact that attributes is a
constant. How should I iterate this deque?

Frederik
 
J

John Harrison

Frederik Himpe said:
I'm implementing a SAX handler with libxml++. I have this piece of code:

void PalamedeParser::eek:n_start_element(const std::string &name, const
AttributeList &attributes) {
AttributeList::iterator it = attributes.begin();

with AttributeList defined as
typedef std::deque< Attribute > xmlpp::SaxParser::AttributeList

On the initialization of the iterator, I got this error:

conversion from
`__gnu_norm::_Deque_iterator<xmlpp::SaxParser::Attribute, const
xmlpp::SaxParser::Attribute&, const xmlpp::SaxParser::Attribute*>' to
non-scalar type `__gnu_norm::_Deque_iterator<xmlpp::SaxParser::Attribute,
xmlpp::SaxParser::Attribute&, xmlpp::SaxParser::Attribute*>' requested

It seems the compiler does not like the fact that attributes is a
constant. How should I iterate this deque?

Use a const iterator.

AttributeList::const_iterator it = attributes.begin();

john
 
F

Frederik Himpe

Use a const iterator.

AttributeList::const_iterator it = attributes.begin();

Hmm, of course. This works fine. I should really practice my C++ more, in
order not to forget such obvious things over time.

Thank you for the quick answer!
Frederik
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,184
Messages
2,570,978
Members
47,561
Latest member
gjsign

Latest Threads

Top