【问题标题】:What C-data type do I have to use?我必须使用什么 C 数据类型?
【发布时间】:2023-03-23 22:45:01
【问题描述】:

我必须调用一个外部函数,它的头部有类似的东西

void asd(unsigned int *&name)

我现在的问题是什么类型的变量是名称?我知道它应该作为一个数组起作用,但我有点困惑,因为传递一个简单的 unsigned-int-array 不起作用。

编辑:

感谢您的帮助,我尝试了:

unsigned int* name[];
asd(feld);

这给了我一个错误,比如“名称的存储大小未知”,但是当我写的时候

unsigned int* name[10];
asd(feld);

我得到“来自 int 类型的临时的 unsigned int& 类型的非常量引用的无效初始化”。现在我真的很困惑。

【问题讨论】:

  • 它是一个指向unsigned int的指针的引用,所以它会接受和unsigned int*的左值。
  • 我对 juanchopanza 的回答没有什么要补充的,所以我没有回答。

标签: c++ arrays


【解决方案1】:

name 是对指向unsigned int 的指针的引用,因此它将接受unsigned int* 左值。例如,

unsigned int* p = nullptr;
asd(p);

通过引用传递的事实意味着函数asd 可以更改传递给它的指针的值,并且调用者可以看到这种更改。

【讨论】:

  • @stefan 谢谢。我的意思是“任何”,但即使这样也是多余的。
猜你喜欢
  • 2021-12-31
  • 1970-01-01
  • 2015-03-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多