For some reason the getter methods doesn't work. They are public, so I have no idea what's wrong.
for (std::vector<Document>:: const_iterator it = v.begin(); it != v.end(); ++it)
{
cout << it->getName() << endl;
counter += it->getLength();
}
error: passing 'const Document' as 'this' argument of 'void Document::getName()' discards qualifiers [-fpermissive] cout << it->getName() << endl;
error: no match for 'operator<<' (operand types are 'std::ostream {aka std::basic_ostream}' and 'void') cout << it->getName() << endl;
error: passing 'const Document' as 'this' argument of 'void Document::getLength()' discards qualifiers [-fpermissive] counter += it->getLength();
error: invalid operands of types 'int' and 'void' to binary 'operator+' counter += it->getLength();
Hmm, is there a way to can we do (int) (it->getLength())
for the last problem
and can we do for the other one:
std::ostringstream value;
value << (*it).getName();
cout << getName << endl;
const
, so you can't call them with aconst_iterator
. It has nothing to do with accessibility and everything to do with const-correctness. And you can't print the result of something returningvoid
. – chrisvoid
to something else. I fail to see the other problem. – chris