从原始指针转换为智能指针

时间:2013-05-06 21:11:06

标签: c++ pointers smart-pointers

我想使用智能指针而不是原始指针。 如何相应地转换此功能?

Node * List::next(const Node * n) const {
    return n->next;
}

1 个答案:

答案 0 :(得分:6)

像这样:

Node * List::next(const Node * n) const {
    return n->next;
}

据我所知,函数next不执行任何所有权转移,因此它不需要关注Node对象的所有权,因此它不会需要改变。 (它不需要是List的成员,也可以是static成员。)