У меня есть следующие:Вектор unique_ptr члена
typedef std::vector<std::unique_ptr<Node>> NodeList;
class Node
{
public:
Node();
Node(NodeType _type);
virtual ~Node();
NodeType getNodeType() const;
Node const* getParentNode() const;
// I want a member function to allow acces to the
// childNodes vector
bool hasChildNodes() const;
void setParent(Node* node);
void appendChild(std::unique_ptr<Node> node);
protected:
NodeType _nodeType;
Node* parentNode;
NodeList childNodes;
};
Я хочу, чтобы пользователь класса, чтобы иметь доступ к ChildNodes (чтение или чтение и запись). Как я могу это достичь?
EDIT
Я пробовал: NodeList & getChildNodes();
и я получаю:
/usr/include/c++/4.8.3/bits/stl_construct.h:75: error: use of deleted function 'std::unique_ptr<_Tp, _Dp>::unique_ptr(const std::unique_ptr<_Tp, _Dp>&) [with _Tp = Node; _Dp = std::default_delete<Node>]'
{ ::new(static_cast<void*>(__p)) _T1(std::forward<_Args>(__args)...); }
^
Не самое лучшее, что можно сделать, но вы всегда можете вернуть ссылку Это. Например, вы можете добавить следующий метод: 'const NodeList & getChildNodes() const {return childNodes; } ' – crayzeewulf