我有一个API采取一些选项:无法从转换 'T [N] [2]' 到 'T [] [2]'
void init_api(const char* options[][2]);
我允许通过一个NULL指针为没有选项可替代地,一个选项阵列,例如这可以被传递:
const char* some_options[][2] = { {"opt1", "val1"},
{"opt2", "val2"},
{0,0}
};
这作品没有问题:
...
init_api(some_options);
... or ...
init_api(NULL);
...
然而,失败编译:
const char* my_options[][2] = NULL; // error C2440: 'initializing' : cannot convert from 'int' to 'const char *[][2]'
if(...) {
my_options = some_options; // error C2440: '=' : cannot convert from 'const char *[4][2]' to 'const char *[][2]'
}
init_api(my_options); // no error here
这到底是怎么回事?有人可以解释这个吗?
为什么?这只是一个指针。当用作函数参数时它可以是NULL。 – 2011-01-13 09:54:03
@Martin - False。数组衰减指针,但指向数组的指针从定义上来说不会是'NULL'。 – 2011-01-13 09:58:25
@Chris:究竟是什么是虚假的*事实*,我*可以*传递NULL到一个函数参数T [] [2]? – 2011-01-13 10:06:56