指向列表内外的第一个对象?

Ash*_*Ash 1 c++ linked-list list

以下哪一项是将第一个对象存储在链表中的更正确的方法?或者有人可以指出每个的优点/缺点.谢谢.

class Node
{
    int var;
    Node *next;

    static Node *first;

    Node()
    {
        if (first == NULL)
        {
            first = this;
            next = NULL;
        }
        else
            //next code here
        }
    }
}

Node* Node::first = NULL;
new Node();
Run Code Online (Sandbox Code Playgroud)

- 要么 -

class Node
{
    int var;
    Node *next;

    Node()
    {
        //next code here
    }
}

Node* first = new Node();
Run Code Online (Sandbox Code Playgroud)

Seb*_*ian 6

后者绝对是可取的.通过使第一个节点指针静态类成员,你基本上是说只会有一个单一的在你的整个程序链表.

第二个示例允许您创建多个列表.