c - 传递对 C 中函数的引用
问题描述
我试图构建一个将引用作为参数的函数。
但是编译给了我一个错误警告,说是预期的')',我不知道是什么问题。
我们不能在 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;
}
推荐阅读
- java - 将 XML 加载到 DOmSource 正在将 xmlns="" 添加到所有 bean 标记
- excel - 在 Excel 和其他计算机的在线版本中使用文件时如何使动画 Gif 工作
- c++ - 为什么我的程序中定义了UNICODE宏
- node.js - 猫鼬 findById() 和 find({someparameter here}) 返回不同的数据吗?
- javascript - npm 错误!无法从路径或包中检测到节点名称
- html - 为什么我的 CSS 网格不响应我的 html?
- windows - 如何从 Windows 10 Pro 运行 Windows Nano Server 容器?
- python - 如何用 if 语句减去一个数字?
- python - 如何通过电子邮件获取 API
- typescript - 打字稿:绑定函数没有重载匹配此调用