我想創建一個返回數組的函數(在一個項目中)。我不太確定我該怎麼做。如何從函數中正確返回數組?
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