Why do linked lists use pointers instead of storing nodes inside of nodes

后端 未结 11 2109
春和景丽
春和景丽 2020-12-07 13:53

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

         


        
11条回答
  •  醉梦人生
    2020-12-07 14:20

    Because this in C++

    int main (..)
    {
        MyClass myObject;
    
        // or
    
        MyClass * myObjectPointer = new MyClass();
    
        ..
    }
    

    is equivalent to this in Java

    public static void main (..)
    {
        MyClass myObjectReference = new MyClass();
    }
    

    where both of them create a new object of MyClass using the default constructor.

提交回复
热议问题