未定义的引用static constexpr char [] [] [英] Undefined reference to static constexpr char[][]
本文介绍了未定义的引用static constexpr char [] []的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图在类中的char char [] []静态公共字段,但在另一个函数这个字段是未定义的。我如何使用consexpr或存在另一个方法init static(字典)数组?
I tried to init char[][] static public field in class but in another function this field is undefined. How I use consexpr or exists another method to init static (dictionary) array?
class A {
public:
constexpr static char dict[][3] = {
"a",
"bb"
};
void print() {
printf(A::dict[1]);
}
};
int main() {
A a;
a.print();
return 0;
}
10未定义引用`A :: dict'
10 undefined reference to `A::dict'
推荐答案
定义需要超出类,而初始化器属于类内。
The definition needs to go outside the class, while the initializer belongs inside the class.
constexpr char A::dict[][3];
这篇关于未定义的引用static constexpr char [] []的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文