static array class variable “multiple definition” C++

痴心易碎 提交于 2019-12-01 04:40:39

You're violating the one definition rule. Move the definition inside an implementation file:

//A.cpp
#include "A.h"
const int A::a[] = {1,2};

The solution you are reffering to, with extern, applies to non-member variables. In your case a is a class member.

You should remove the "const int A::a[] = {1,2};" line from the header file. Put this definition line in one of you .cpp files. Then you can include the header file several times where you need it.

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