I've worked with linked lists before extensively in Java, but I'm very new to C++. I was using this node class that was given to me in a project just fine
class Node
{
public:
Node(int data);
int m_data;
Node *m_next;
};
but I had one question that wasn't answered very well. Why is it necessary to use
Node *m_next;
to point to the next node in the list instead of
Node m_next;
I understand that it is better to use the pointer version; I'm not going to argue facts, but I don't know why it's better. I got a not so clear answer about how the pointer is better for memory allocation, and I was wondering if anyone here could help me understand that better.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…