昨天心血来潮,想用类封装线段树(具体可以见这篇文章),但封装时,我遇到了一个问题。
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 是定义全局变量。所以为什么要两个一起用呢?