return 问题
怎样return 一列数组呀?比如说return a[1],a[2],...a[n]
[此贴子已经被作者于2007-11-19 16:07:21编辑过]
[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]
都不看别人的回复吗?
在main()进行释放.
好像在Dev-C++ 中没有办法编译通过.
它会指出源文件没有编译
可以。
如果返回类型是const int*那就不可以。
在main()进行释放.
好像在Dev-C++ 中没有办法编译通过.
它会指出源文件没有编译
任何标准c++编译器均可通过!