c++ - 指针变量赋值

标签 c++ pointers linked-list

<分区>

我创建了一个结构:

struct time
{
    int hours;
    int minutes;
    int seconds;
    double total_time;
    double price;

    time* next;
    time* back;
};

我已经创建了 2 个指向该结构的指针:

time* traverse, head;

我想将 head 的位置指向与 head 相同的位置:

traverse = new time;
    head = traverse; // Error here

为什么我在作业中遇到错误?

最佳答案

写作时

time* traverse, head;

星星只影响第一个变量。将您的声明更改为

time *traverse, *head;

错误应该消失了。

关于c++ - 指针变量赋值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13751274/

相关文章:

c++ - C++ 中的动态数组(指针数组还是新数组?)

c++ - 为什么我不能执行 tupleVar.get(3) 或 .get<3>()?

c - 如何修改已传递给 C 函数的指针?

c++ - const - 它不应该改变吗

c++ - 实现链表的麻烦

c++ - C++ 中 STL::MAP 的内部实现

c++ - 异常声明错误

c++ - 为什么 C++ 将指针和指针数组视为同一事物?

go - 在 Go 语言中返回其结构地址的方法

c++ - 如何找到链表的结尾