标题:问一个语法问题
取消只看楼主
leeco
Rank: 4
等 级:贵宾
威 望:10
帖 子:1026
专家分:177
注 册:2007-5-10
结帖率:50%
 问题点数:0 回复次数:2 
问一个语法问题
想让函数返回一个数组指针,函数类型应该如何写?
搜索更多相关主题的帖子: 问题 如何 
2007-10-13 22:46
leeco
Rank: 4
等 级:贵宾
威 望:10
帖 子:1026
专家分:177
注 册:2007-5-10
得分:0 
嗯,不错,这样可以的。谢谢了
2007-10-13 23:56
leeco
Rank: 4
等 级:贵宾
威 望:10
帖 子:1026
专家分:177
注 册:2007-5-10
得分:0 
以下是引用HJin在2007-10-14 2:07:49的发言:

#include <iostream>
using namespace std;

/**
Explanation:

The right-left rule:

0. locate the specififer: f in this exmaple
1. look at its right: () in this case, hence f is a function
2. look at its left: * in this case, hence f returns a pointer
3. look at (*f())'s right: [10], hence f is a function which returns a pointer to an array of 10 elements
4. look at (*f())'s left: int, hence f is a function which returns a pointer to an array of 10 ints.
*/
int (*f())[10];


int main()
{
f();

return 0;
}

int (*f())[10]
{
int (*p)[10] = new int[5][10];

return p;
}

强的。很好

2007-10-18 17:39



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-177396-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.286573 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved