我想创建一个返回数组的函数(在一个项目中)。我不太确定我该怎么做。如何从函数中正确返回数组?
int worker::*codebook(UnitType type){
int code[12];
if (type == UnitTypes::center){
int temp[12] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1};
code=temp;
}
return code;
}
其中worker
是类和unitType
枚举。我在头文件中定义的功能如下:
int *codebook(UnitType type);
我的问题是这样的:
cannot convert from 'int' to 'int Worker::*
这个任何想法?
可能重复的[C++返回数组从函数](http:// stackoverflow .com/questions/8745260/c-return-array-from-function) – 2012-02-07 16:16:42