return 问题
怎样return 一列数组呀?比如说return a[1],a[2],...a[n]
2007-11-19 15:53
[此贴子已经被作者于2007-11-19 16:07:21编辑过]

2007-11-19 16:06
2007-11-20 11:17
2007-11-20 12:18
2007-11-20 13:10
[CODE]
#include <iostream>
using namespace std;
/**
The caller is responsile for freeing the memory.
*/
int* f(int n)
{
int* a = new int[n];
for(int i=0; i<n; ++i)
a[i] = n;
return a;
}
int main()
{
int n=6;
int* b = f(n);
for(int i=0; i<n; ++i)
cout<<b[i]<<" ";
cout<<endl;
delete [] b;
return 0;
}
[/CODE]
都不看别人的回复吗?

2007-11-20 13:41
2007-11-20 16:00
在main()进行释放.
好像在Dev-C++ 中没有办法编译通过.
它会指出源文件没有编译

2007-11-20 20:43
可以。
如果返回类型是const int*那就不可以。

2007-11-20 21:42
在main()进行释放.
好像在Dev-C++ 中没有办法编译通过.
它会指出源文件没有编译
任何标准c++编译器均可通过!

2007-11-20 21:43