[英]unresolved external symbol structs
error LNK2001: unresolved external symbol "public: static int WrappedVector::_N" (?_N@WrappedVector@@2HA) 错误LNK2001:无法解析的外部符号“ public:static int WrappedVector :: _ N”(?_N @ WrappedVector @@ 2HA)
header.h header.h
struct WrappedVector
{
static int _N;
double *_x;
};
main.cpp main.cpp中
const int WrappedVector::_N = 3;
i don't understand whats wrong 我不明白怎么了
Just change the definition 只需更改定义
int WrappedVector::_N = 3; // Note no const
see LIVE DEMO1 观看LIVE DEMO1
or the declaration 或声明
struct WrappedVector {
static const int _N;
// ^^^^^
double *_x;
};
see LIVE DEMO2 观看LIVE DEMO2
consistently. 一致。
If you need the latter form ( static const int
) you can also initialize it directly in the declaration: 如果需要后一种形式(
static const int
),也可以直接在声明中对其进行初始化:
struct WrappedVector {
static const int _N = 3;
// ^^^
double *_x;
};
see LIVE DEMO3 观看LIVE DEMO3
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.