加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c – 奇怪的函数语法:auto(* f3)(int n) – > int(*)[n];

发布时间:2020-12-16 09:59:31 所属栏目:百科 来源:网络整理
导读:我遇到了这种奇怪的函数语法: const int n = 3;auto (*f3)(int n)-int (*)[n]; //error: parameter 'n' as array bound 在cppreference.com上阅读this page的范围. 虽然第二个陈述是错误的,但你如何解释呢? (假设范围错误已得到纠正) 我认为第一部分是指向
我遇到了这种奇怪的函数语法:

const int n = 3;

auto (*f3)(int n)->int (*)[n]; //error: parameter 'n' as array bound

在cppreference.com上阅读this page的范围.

虽然第二个陈述是错误的,但你如何解释呢? (假设范围错误已得到纠正)

我认为第一部分是指向函数的指针,但它的部分来自于
– >那些让我难过的东西.

有人能指出我正确的方向吗?谢谢

解决方法

Although the second statement is an error,how do you interpret it? (assuming the scope error was rectified)

示例显示了btw 2个案例的区别:

const int n = 3;

int (*(*f2)(int n))[n];

基本上相当于:

const int n = 3;

int (*(*f2)(int n1))[n];

const int n = 3;

auto (*f3)(int n)->int (*)[n];

相当于:

const int n = 3;

auto (*f3)(int n1)->int (*)[n1];

和文章说明了原因.如果您的意思是修复此代码:

const int n = 3;

auto (*f3)(int n1)->int (*)[n];

然后它会声明一个指向函数的指针,该函数接受一个int类型的参数并返回指向3个int的数组的指针.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读