“array bound is not an integer constant before ']' token” when using multiple files [duplicate]

☆樱花仙子☆ 提交于 2019-12-02 12:15:41

To be usable as a constant expression, a constant variable must be defined, not just declared. Assuming you want to use it from multiple translation units, remove the extern to give it internal linkage (so it can be defined in any unit that needs it), and add an initialiser to give the value.

Also, remove the local array declaration from the constructor. I'm not sure what you want that to do, but it doesn't do anything useful.

the constant tweaks can't be in a header because then I get multiple declaration errors

That's because extern gives them external linkage, making them subject to the One Definition Rule.

I thought declaring them as extern would tell it to find the constant value elsewhere

It tells the compiler that the value will be available at run-time; but does not provide the compiler with the definition. The definition is needed to use the value in a constant expression.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!