繁体   English   中英

在&符号之前我需要放什么?

[英]What do I need to put before the ampersand?

获取extractMin的参数行的以下错误:

randmst.c:129:错误:在'&'标记之前预期';',','或')'

如果我没有粘贴足够的代码以使错误显而易见,请告诉我。

//the heap functions

//based on p. 163 of clrs
VertexPointer
extractMin(VertexPointer *heap, int &heap_size){
    VertexPointer max = heap[0];
    (*heap[0]).key = 100;
    heap_size = heap_size - 1;
    minHeapify(heap, heap_size, 1);
    return max;
}

您无法在C执行此extractMin(VertexPointer *heap, int &heap_size) - 将其更改为extractMin(VertexPointer *heap, int *heap_size)

C中没有Pass-by-reference。所以你应该有这样的东西:

extractMin(VertexPointer *heap, int *heap_size){
    VertexPointer max = heap[0];
    (*heap[0]).key = 100;
    *heap_size = *heap_size - 1;
    minHeapify(heap, *heap_size, 1); 
    return max;
}

&用于获取变量的地址,因此在调用函数时,您应该这样调用它:

extractMin(someAddress_to_heap, someAddress_to_heap_size)

通过引用传递在C中不起作用,通过引用和传递地址存在差异。 C ++支持传递refrence但C不支持。 将您的代码更改为

VertexPointer
extractMin(VertexPointer *heap, int *heap_size)

暂无
暂无

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

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