const int num = 16;
struct inputs{
double X1[num];
double X2[num];
};
给我一个错误:
error: variably modified ‘X1’ at file scope
“X2”也是如此。
不过我记得上面的C++没问题,上面的没问题(我可能会误认为是C++)。
谁能帮我解释一下?
最佳答案
我可以给你指点 C FAQ: I don't understand why I can't use const values in initializers and array dimensions .
它基本上说的是 num
不是真正的常量,它只是只读的。要获得真正的常量,您需要 #define num 16
。
同样在该页面上:C 在这方面不同于 C++。
关于c++ - C 和 C++ 的数组大小声明差异,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8002765/