问题描述
|
请告诉我,为什么gcc链接程序给我以下错误:\“ test_class :: test_struct :: constvar \”,引用自test_class.o中的__ZN12lu_test_class27test_struct6constvar $ non_lazy_ptr?
我的代码(test_class.h):
class test_class
{
struct test_struct
{
static const int constvar = 0;
};
};
所有对constvar的引用都以通常的静态成员访问形式在test_class范围内:test_struct :: constvar。
解决方法
在类外提供静态成员的定义
const int test_class::test_struct::constVar;
这对我有用。