通过函数传递双指针问题错误

时间:2019-07-18 10:04:28

标签: c++ c pointers double-pointer

我有一个二维数组,我想通过一个函数

char blendModeOptions[18][16]={"Normal","Darken","Multiply","Color Burn","Linear Burn","Lighten","Screen","Color Dodge","Linear Dodge","Overlay","Soft Light","Hard Light",
    "Vivid Light","Linear Light","Pin Light","Difference","Exclusion","Hue"};

blendMode = KIT_CreateSelectOption(blendModeOptions,18,&blendModeRect);

,函数的声明为:

KIT_SelectOption * KIT_CreateSelectOption(char ** options,int size ,SDL_Rect * rect);

我收到警告:

note: expected 'char **' but argument is of type 'char (*)[16]'

在函数内部,我通过此参数int KIT_AddOption(KIT_SelectOption *box, const char * option);调用函数KIT_AddOption(box,options[i]);

当我在KIT_AddOption的这一行代码中时,我的程序崩溃了

strcpy(opt->name,option);

我尝试使用char * option[16]代替了char ** option,但是它不起作用。

1 个答案:

答案 0 :(得分:7)

您需要将数组定义为指针数组,而不是2D char数组。

char *blendModeOptions[]={"Normal","Darken","Multiply","Color Burn","Linear Burn","Lighten","Screen","Color Dodge","Linear Dodge","Overlay","Soft Light","Hard Light",
"Vivid Light","Linear Light","Pin Light","Difference","Exclusion","Hue"};