当尝试使用 boost :: indirect_iterator 时,我得到“int不是类,结构或联合类型”。 谁能看到我哪里出错?
#include <iostream>
#include <set>
#include <boost/iterator/indirect_iterator.hpp>
// Expose the itererator if the container stores pointers.
class MyCollection
{
public:
// Iterator interface
typedef boost::indirect_iterator<int*> iterator;
iterator begin() { return objects.begin(); }
iterator end() { return objects.end(); }
private:
std::set<int*> objects;
};
int main()
{
MyCollection myCollection;
for(MyCollection::iterator iterator = myCollection.begin(); iterator != myCollection.end(); iterator++)
{
std::cout << " " << *iterator;
}
return 0;
}
答案 0 :(得分:3)
事实证明你必须使用:
typedef boost::indirect_iterator<std::set<int*>::iterator> iterator;