gpt4 book ai didi

c++ - 错误 : cast to incomplete array type "int []" is not allowed

转载 作者:行者123 更新时间:2023-11-28 01:25:57 26 4
gpt4 key购买 nike

我想得到VA_ARGS的长度

我用了这个问题的答案https://stackoverflow.com/a/2124433/7388699但如果不起作用!

#define PIN_ARRAY_LENGTH(...) ((size_t)(sizeof((int[]){__VA_ARGS__})/sizeof(int)))

size_t c = PIN_ARRAY_LENGTH(1, 5, 7, 9);

我也试过

size_t x = sizeof((int[]){ 1, 6, 8 }) / sizeof(int);

它不编译,我得到错误:不允许转换为不完整的数组类型“int []”

最佳答案

复合文字是不可能的,但您可以通过 typedef 创建所需的数组右值:

using int_c_array = int[];

#define count_args(...) \
(sizeof(int_c_array {__VA_ARGS__}) / sizeof(int))

关于c++ - 错误 : cast to incomplete array type "int []" is not allowed,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53872180/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com