关于 const 和 static
  • 板块学术版
  • 楼主Zvelig1205
  • 当前回复10
  • 已保存回复10
  • 发布时间2022/10/21 07:49
  • 上次更新2023/10/27 06:42:50
查看原帖
关于 const 和 static
413020
Zvelig1205楼主2022/10/21 07:49

昨天心血来潮,想用类封装线段树(具体可以见这篇文章),但封装时,我遇到了一个问题。

class NormalBalanceTree {
public:
	const static int N = 1e5 + 7;
	
	struct Seg_Tree {
		int lc, rc, sum;
	}T[N << 2];
	
	int rot, cnt;
};

这个是变量的封装,其中 N 的定义必须要 const 和 static 一起用,而 const int 和 static int 都报错。

我了解到的 const 是定义常量,static 是定义全局变量。所以为什么要两个一起用呢?

2022/10/21 07:49
加载中...