在 C++ 中返回数组

2022-01-19 00:00:00 return arrays 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.

相关文章