我有一个像这样的课程:
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
怎么了?为什么未声明值?完整来源