Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Now I have a definition
list<Node*> _nodes;
and a function
Node* Directory::getChild(int index) { }
then how can I add a return in the getChild()?
getChild()
可能是这样的:
Node* Directory::getChild(int index) { assert(index >= 0 && index < _nodes.size()); list<Node*>::iterator it = _nodes.begin(); advance(it, index); return *it; }
请注意,如果您需要随机访问,std::list则对于容器类来说是一个糟糕的选择。
std::list