简体   繁体   中英

Indirection operator on const_iterator error

This code

std::ostream& operator<<( std::ostream& output, const Array& a) {
    if (a.empty()) {
        output << Structural::BEGIN_ARRAY << Structural::END_ARRAY;

    } else {
        output << Structural::BEGIN_ARRAY << std::endl;
        OutputFilter<Indenter> indent(output.rdbuf());
        output.rdbuf(&indent);

        for (Array::const_iterator i = a.begin(); i != a.end(); ++i) {
            if (i != a.begin()) {
                output << Structural::VALUE_SEPARATOR << std::endl;
            }

            output << *i; // <--- Error is here...

        }

        output.rdbuf(indent.getDestination());

        output << std::endl << Structural::END_ARRAY;

    }

    return output;

}

produces the following error in Apple LLVM compiler 4.2:

Indirection requires pointer operand ('Array::const_iterator' (aka 'int') invalid)

However, if I compile this code in LLVM GCC 4.2, it works fine. Any ideas?

It looks like Array::const_iterator is of type int . You cannot dereference an int (in contrast to a pointer or STL iterator).

清理,重新启动XCode,清理,然后重建。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM