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);

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-10-03
  • 2022-01-01
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-10-12
  • 2021-05-05
  • 2021-09-10
  • 2022-12-23
  • 2022-12-23
  • 2021-08-18
相关资源
相似解决方案