0

我有一个像这样的课程:

class VectorAttrIterator : public AttrIterator {
    vector<AttrValue>* values;
    vector<AttrValue>::iterator it;
public:
    VectorAttrIterator(vector<AttrValue>* _values) : values(_values) {
        it = (*values).begin();
    };

    bool hasNext() {
        return it != (*values).end();
    };

    AttrValue next() {
        int ret = (*it);
        it++;
        return ret;
    };

    ~VectorAttrIterator() {
        delete values;
    };
};

有用。然后我想做一些类似的事情unordered_set

class UnorderedSetAttrIterator : public AttrIterator {
    unordered_set<AttrValue>* values;
    unordered_set<AttrValue>::iterator it;
public:
    UnorderedSetAttrIterator(vector<AttrValue>* _values) : values(_values) {
        it = (*values).begin();
    };

    bool hasNext() {
        return it != (*values).end();
    };

    AttrValue next() {
        int ret = (*it);
        it++;
        return ret;
    };

    ~UnorderedSetAttrIterator() {
        delete values;
    };
};

唯一的更改vector是更改为unordered_set和类重命名。但我收到如下错误:

Error   42  error C2065: 'values' : undeclared identifier   h:\dropbox\sch\cs3202\code\source\includes\iterator.h   40
Error   43  error C2228: left of '.begin' must have class/struct/union  h:\dropbox\sch\cs3202\code\source\includes\iterator.h   40
Error   44  error C2440: 'initializing' : cannot convert from 'std::vector<_Ty> *' to 'std::tr1::unordered_set<_Kty> *' h:\dropbox\sch\cs3202\code\source\includes\iterator.h   39
Error   45  error C2439: 'UnorderedSetAttrIterator::values' : member could not be initialized   h:\dropbox\sch\cs3202\code\source\includes\iterator.h   39
Error   46  error C2065: 'it' : undeclared identifier   h:\dropbox\sch\cs3202\code\source\includes\iterator.h   44
Error   47  error C2065: 'values' : undeclared identifier   h:\dropbox\sch\cs3202\code\source\includes\iterator.h   44
Error   48  error C2228: left of '.end' must have class/struct/union    h:\dropbox\sch\cs3202\code\source\includes\iterator.h   44
Error   49  error C2065: 'it' : undeclared identifier   h:\dropbox\sch\cs3202\code\source\includes\iterator.h   48
Error   50  error C2065: 'it' : undeclared identifier   h:\dropbox\sch\cs3202\code\source\includes\iterator.h   49
Error   51  error C2065: 'values' : undeclared identifier   h:\dropbox\sch\cs3202\code\source\includes\iterator.h   54

怎么了?为什么未声明值?完整来源

4

1 回答 1

1

看起来这条线是这个问题:

UnorderedSetAttrIterator(vector<AttrValue>* _values) : values(_values) {

您是否忘记将参数类型从 更改vectorunordered_set

于 2013-03-29T13:54:46.590 回答