在二进位搜索树的类中,我有一个键和一个指向结构中左右节点的指针。
我在类的copy函数中得到parasoft错误,因此建议将代码更改为:
BinaryTree::Node* BinaryTree::copyHelper(const Node* other)
{
if(other == NULL)
{
return NULL; // If there's no Node to copy, return NULL.
}
else
{
//Node* newNode = new Node;
typedef std::unique_ptr<Node> NodePtr;
NodePtr newNode(new Node);
if(newNode)
{
newNode->name = other->name;
newNode->left = copyHelper(other->left);
newNode->right = copyHelper(other->right);
}
return newNode;
}
}现在,我收到了newNode返回语句中的一个错误:
IntelliSense:从
NodePtr到BinaryTree::Node *没有合适的转换函数
有什么想法吗?
发布于 2012-05-02 14:40:33
这是你的职责:
BinaryTree::Node* BinaryTree::copyHelper(const Node* other) { ...}它返回一个BinaryTree::Node*,并且应该返回一个unique_ptr<Node>
std::unique_ptr<BinaryTree::Node> BinaryTree::copyHelper(const Node* other) { ...}https://stackoverflow.com/questions/10415636
复制相似问题