在 C++ 中返回数组 [英] Return array in C++

查看:29
本文介绍了在 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++ 中返回数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆