我一直在使用C#一段时间,而回到C++是一件令人头疼的事情。我试图从C++中将我的一些练习与C++一起获得,但是我发现了一些阻力,我很乐意接受你的帮助。如何在不暴露容器的情况下公开迭代器?
我想揭露迭代器像这样的类:
template <class T>
class MyContainer
{
public:
// Here is the problem:
// typedef for MyIterator without exposing std::vector publicly?
MyIterator Begin() { return mHiddenContainerImpl.begin(); }
MyIterator End() { return mHiddenContainerImpl.end(); }
private:
std::vector<T> mHiddenContainerImpl;
};
上午我试图在东西是不是有问题?我应该只是typedef std :: vector < T> :: iterator?我希望对刚刚取决于迭代器,而不是实现容器...
同样看到这个[问题](http://stackoverflow.com/questions/127009/returning-an-any-kind-of-input-iterator-instead-of-a-vectoriterator-or-a -listit) – 2008-10-01 12:11:40