1

我有 3 个带有整数(枚举)的数组:

static int *openEnv[] = {INGMenuItemLogon,INGMenuItemSpace,INGMenuItemAppointment,INGMenuItemInfo,INGMenuItemSettings};
static int *closedEnv[] = {INGMenuItemLogoff,INGMenuItemSpace,INGMenuItemOverview,INGMenuItemAccounts,INGMenuItemTransfer,INGMenuItemAnalyse,INGMenuItemAppointment,INGMenuItemInfo,INGMenuItemSettings};
int *currentEnv[];

如果用户点击一个按钮,我希望将currentEnv其更改为openEnvclosedEnv

- (void) tap
{
    if( closed ) currentEnv = closedEnv;
    else currentEnv = openEnv;
}

但这会产生构建错误。 openEnv并且closedEnv有 2 种不同的尺寸,我应该怎么做才能复制它?我该怎么做才能引用或复制到它的静态数组?

4

3 回答 3

2

尝试这个:

static int *openEnv[] = {INGMenuItemLogon,INGMenuItemSpace,INGMenuItemAppointment,INGMenuItemInfo,INGMenuItemSettings};
static int *closedEnv[] = {INGMenuItemLogoff,INGMenuItemSpace,INGMenuItemOverview,INGMenuItemAccounts,INGMenuItemTransfer,INGMenuItemAnalyse,INGMenuItemAppointment,INGMenuItemInfo,INGMenuItemSettings};
//int *currentEnv[];
int **currentEnv;

- (void) tap
   {
     if( closed ) 
        currentEnv = closedEnv;
     else 
        currentEnv = openEnv;
   }
于 2013-04-25T10:43:09.443 回答
1

只需使用:int ** currentEnv = <the array>

于 2013-04-25T10:44:13.573 回答
1

您已经声明了指向 int的指针数组。正确的是

static int openEnv[] = {INGMenuItemLogon,INGMenuItemSpace,INGMenuItemAppointment,INGMenuItemInfo,INGMenuItemSettings};
static int closedEnv[] = {INGMenuItemLogoff,INGMenuItemSpace,INGMenuItemOverview,INGMenuItemAccounts,INGMenuItemTransfer,INGMenuItemAnalyse,INGMenuItemAppointment,INGMenuItemInfo,INGMenuItemSettings};

(不带星*号)声明 int 数组,以及

int *currentEnv;

作为指向 int 的指针。然后您可以分配 egcurrentEnv = openEnv以便currentEnv指向 的元素openEnv

于 2013-04-25T10:50:54.653 回答