如何在C++中创建静态类?我应该可以这样做:
cout << "bit 5 is " << BitParser::getBitAt(buffer, 5) << endl;
Run Code Online (Sandbox Code Playgroud)
假设我创建了这个BitParser类.将在哪些BitParser类定义是什么样子?
我最近遇到过这个:
static enum Response{
NO_ERROR=0,
MISSING_DESCRIPTOR,
...
};
Run Code Online (Sandbox Code Playgroud)
它在Microsoft VS2005下编译和工作.但是,我不确定'静态'修饰符应该做什么.它与以下有何不同?
enum Response {
NO_ERROR=0,
MISSING_DESCRIPTOR,
...
};
Run Code Online (Sandbox Code Playgroud) static struct astr {
int a;
};
static const struct astr newastr = {
.a = 9,
};
Run Code Online (Sandbox Code Playgroud)
我得到:警告:空声明中无用的存储类说明符
如果我把它改成
static struct astr {
int a;
} something;
Run Code Online (Sandbox Code Playgroud)
那么警告将被修复。
以下也没有给出该警告
struct astr {
int a;
};
static const struct astr newastr = {
.a = 9,
};
Run Code Online (Sandbox Code Playgroud)
有人可以解释一下这是怎么回事吗?