* ptr2 = ptr是什么意思?

问题描述 投票:-1回答:2

我目前正在为我的一门课制作一个双向链接列表。我们的压力测试之一如下所示:

//Delcarations
DLList<string> list;
DLList<string>* list2;

list.clear();                         //Clears the list
list2 = &list;                        //Sets the values to be the same
list.addHead("I'm meant to be here"); //Adds this as head of both lists
*list2 = list;                        //Unsure what this does
printFunc(*list2);                    //prints the contents of the list

我的输出框只显示listlist2都变成NULL,当我打印*list2时它打印NULL

我的问题是:

  1. *list2 = list实际在做什么?
  2. 为什么我的值都都变成NULL?
c++ pointers doubly-linked-list
2个回答
1
投票

*list2 = list正在更改数据的值


1
投票

您的两条评论不正确。也许更正的评论会使情况更加清晰?

© www.soinside.com 2019 - 2024. All rights reserved.