const_iterator错误的间接运算符

时间:2013-05-15 20:13:31

标签: c++ llvm-gcc llvm-clang const-iterator

此代码

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;

}

在Apple LLVM编译器4.2中产生以下错误:

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

但是,如果我在LLVM GCC 4.2中编译此代码,它可以正常工作。有什么想法吗?

2 个答案:

答案 0 :(得分:1)

看起来Array::const_iterator的类型为int。你不能取消引用int(与指针或STL迭代器相反)。

答案 1 :(得分:1)

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