C语言 错误:间接需要指针操作数

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/29331160/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 11:48:29  来源:igfitidea点击:

error: indirection requires pointer operand

cpointers

提问by jsmith102894

I have the following functions, an initializeHeap function which takes in no arguments and outputs a Heap struct which I have defined. And an insertNode function which takes in a pointer to a heap struct and the number to be added to the heap. I call them in the main function as such:

我有以下函数,一个 initializeHeap 函数,它不接受任何参数并输出我定义的 Heap 结构。还有一个 insertNode 函数,它接收一个指向堆结构的指针和要添加到堆中的数字。我在主函数中这样调用它们:

h = initializeHeap();
Heap *p = *h;
insertNode(p,5);
insertNode(p,7);
insertNode(p,3);
insertNode(p,2);

I get this error when trying to do this:

尝试执行此操作时出现此错误:

error: indirection requires pointer operand

Any ideas? I can post more code if needed.

有任何想法吗?如果需要,我可以发布更多代码。

The struct Heap and function initializeHeap() are as follows:

struct Heap 和函数 initializeHeap() 如下:

typedef struct node{
    int data;
}Node;

typedef struct heap{
    int size;
    Node *dataArray;
}Heap;

Heap initializeHeap(){
    Heap heap;
    heap.size = 0;
    return heap;
}

回答by ouah

Change:

改变:

Heap *p = *h;

to

Heap *p = &h;

his a Heapstructure object, use &operator to get a pointer to the structure object.

h是一个Heap结构对象,使用&操作符得到一个指向结构对象的指针。