Return array in C++(在 C++ 中返回数组)
问题描述
我是一个完全的 C++ 菜鸟,我在从我的方法返回一个数组时遇到了一些麻烦.我有一个带有以下方法声明的头文件:
I am a total C++ noob, and I am having some trouble returning an array from my methods. I have a header file with the following method declaration:
virtual double[]
echoDoubleArray(double[] doubleArray, int arraySize) throw (RemoteException);
这给了我以下错误:
../common/EchoService.h: At global scope:
../common/EchoService.h:25: error: expected unqualified-id before ‘[’ token
返回数组的正确方法是什么?
What is the correct way to return an array?
推荐答案
C++ 不能很好地处理非本地数组,你更可能应该使用像 std::array<double,10> 这样的实际容器;
或 std::vector
.我认为不可能从函数返回数组.
C++ doesn't play nice with non-local arrays, more likely you should be using an actual container like std::array<double,10>
or std::vector<double>
. I don't think it's possible to return an array from a function.
这篇关于在 C++ 中返回数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 C++ 中返回数组


基础教程推荐
- 如何通过C程序打开命令提示符Cmd 2022-12-09
- 如何在 C++ 中初始化静态常量成员? 2022-01-01
- 在 C++ 中计算滚动/移动平均值 2021-01-01
- 静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么? 2021-01-01
- 如何检查GTK+3.0中的小部件类型? 2022-11-30
- C++结构和函数声明。为什么它不能编译? 2022-11-07
- 我有静态或动态 boost 库吗? 2021-01-01
- 常量变量在标题中不起作用 2021-01-01
- 这个宏可以转换成函数吗? 2022-01-01
- 如何将 std::pair 的排序 std::list 转换为 std::map 2022-01-01