c++ 静态变量报错 undefined reference to static members

 

c++中静态变量不但要在头文件中declare,还要在实现的cpp中declare。当然也可以赋个初始值。

class foo
{
	int _i;

	public:
		foo(int i) : _i(i) {}
};

class bar
{
	public:
		static int j;
		static foo f;
};

int bar::j = 0;
foo bar::f(1);

c++ 静态变量报错 undefined reference to static members,布布扣,bubuko.com

c++ 静态变量报错 undefined reference to static members

上一篇:c语言_头文件_windows.h


下一篇:Python中的几种数据类型