int Test::i; 行在下面的程序中做了什么。有人请解释
// Assume that integers take 4 bytes.
#include<iostream>
using namespace std;
class Test
{
static int i;
int j;
};
int Test::i;
int main()
{
cout << sizeof(Test);
return 0;
}
最佳答案
这是定义类的 static
成员的语法。它将 Test::i
初始化为 0
。
要给它另一个值,你可以这样做
int Tent::i = 42;
关于c++ - 代码中对象的大小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13738346/