【转载】让c++ 函数返回一个数组
2024-10-12 19:44:52
在c++中是不允许数组作为函数的返回值的 int [] someFunction( ); //ILLEGAL 要想实现函数返回一个数组,那返回对应数组里面类型的指针 you must return a pointer to the array base type and have the pointer point to the array. So, the function declaration would be as follows:
int* someFunction( ); //Legal int* doubler( int a[], int size)
{
int* temp = new int[size];
for ( int i =; i < size; i++)
temp[i] = *a[i];
return temp;
} 调用 int a[] = {, , , , };
int* b;
b = doubler(a, ); delete[] b
最新文章
- 修改Eclipse的 workspace目录
- Linux用户切换
- 手把手教你调试Linux C++ 代码(一步到位包含静态库和动态库调试)
- Metatable让我从心认知了Lua(相知篇)
- Linux系统文件访问控制列表
- 使用struts taglib导致java.lang.NullPointerException: Module &#39;null&#39; not found.
- CXF之五 拦截器Interceptor
- cocos2d-x 纹理源码分析
- 单点登录CAS使用记(七):关于服务器超时以及客户端超时的分析
- C# 初识Ref和Out
- foreach的用法(转)
- 大道至简第一章观后感——java伪代码
- oracle导入dmp文件的2种方法
- android 常用方法集合
- 使用tp访问数据库时提示错误: &#39;PDO&#39; not found, 和not defined constant mysql_attr_init_command 和call an undefined function Think\Template\simpleXml_load_string()函数
- 性能测试LR学习笔录 -2
- WebGL和ThreeJs学习5--ThreeJS基本功能控件
- 人工智能有简单的算法吗?Appendix: Is there a simple algorithm for intelligence?
- 如何成为java架构师(转载)
- Mercedes BENZ C5 SD Connect Xentry Tab Kit Technical Support
热门文章
- CDH 不能监控hadoop状态
- Android Material Design:基于CoordinatorLayout实现向上滚动导航条ToolBar滚出、向下滚动导航条滚出
- 获取月份对应的day
- GetProperties(BindingFlags)说明
- 使用WIF实现单点登录Part II —— Windows Identity Foundation基本原理
- UCOS2_STM32F1移植详细过程(二)
- wpf 动画 2个窗体切换
- static 与 final 修饰符
- Java求职面试准备之常见算法
- 在.net程序中使用System.Net.Mail来发送邮件