简体   繁体   English

难以理解 C++ 中的链表实现

[英]Difficulty to understand linked list implementation in C++

I found this C++ linked list implementation in Geeks for Geeks.我在 Geeks for Geeks 中找到了这个 C++ 链表实现。 For the code Click here获取代码请点击这里

Here from line no.从这里开始。 16->22 it is written 16->22

Node *head = NULL;
Node *second = NULL;
Node *last = NULL;    
head = new Node();
second = new Node();
last = new Node();

I understand我明白

  • Three pointers are initialized with value NULL and then later three instances of the class are created.三个指针被初始化为NULL ,然后创建该类的三个实例。

But what I don't understand is但我不明白的是

  • Where the class objects are created and创建类对象的位置和
  • From where the pointers are getting the addresses to point to.指针从哪里获取要指向的地址。
  • And if I keep any data in private how to access it later then in this implementation because .如果我将任何数据保密,那么稍后在此实现中如何访问它,因为. operator is giving error操作员给出错误

Where the class objects are created创建类对象的位置

The allocating new -expression acquires the memory from the free store.分配new表达式从空闲存储中获取内存。

From where the pointers are getting the addresses to point to.指针从哪里获取要指向的地址。

The new -expression returns the pointer to the object that it created. new表达式返回指向它创建的对象的指针。

how to access it later以后如何访问

By indirecting through the pointer using an indirection operator.通过使用间接运算符通过指针间接。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM