extern const char* const SOME_CONSTANT giving me linker errors

假如想象 提交于 2019-11-29 09:49:30

The problem could be that the extern declaration is not visible in the source file defining the constant. Try repeating the declaration above the definition, like this:

extern const char* const SOME_CONSTANT;  //make sure name has external linkage
const char* const SOME_CONSTANT = "test";  //define the constant

most probably you forgot to include your header in your implementation file

anyway, add the keyword extern to the definition

without an extern declaration it has internal linkage and is thus not visible to the linker

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