我试图构建一个以引用作为参数的函数。
但是编译报错了,说expected')',不知道是什么问题。
我们不能在 C 中使用引用作为参数吗?
以下是代码段。
typedef struct Qnode{
struct Qnode* first;
struct Qnode* rear;
int value;
}Queue;
int init_Queue(Queue &q) //expected')' as the compiler warned me.
{
return 1;
}
我应该使用指针而不是引用作为参数吗??
最佳答案
C 没有引用。这是一个 C++ 结构。
您需要更改函数以接受指针。
int init_Queue(Queue *q)
{
printf("value=%d\n", q->value);
return 1;
}
关于c - 传递对 C 中函数的引用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54723653/