mirror of
https://github.com/Light-City/CPlusPlusThings.git
synced 2026-02-03 10:33:25 +08:00
update
This commit is contained in:
33
basic_content/sizeof/static.cpp
Normal file
33
basic_content/sizeof/static.cpp
Normal file
@@ -0,0 +1,33 @@
|
||||
/**
|
||||
* @file static.cpp
|
||||
* @brief 静态数据成员
|
||||
* 静态数据成员被编译器放在程序的一个global data members中,它是类的一个数据成员,但不影响类的大小。不管这个类产生了多少个实例,还是派生了多少新的类,静态数据成员只有一个实例。静态数据成员,一旦被声明,就已经存在。
|
||||
* @author 光城
|
||||
* @version v1
|
||||
* @date 2019-07-21
|
||||
*/
|
||||
|
||||
#include<iostream>
|
||||
using namespace std;
|
||||
class A
|
||||
{
|
||||
public:
|
||||
char b;
|
||||
virtual void fun() {};
|
||||
static int c;
|
||||
static int d;
|
||||
static int f;
|
||||
};
|
||||
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
|
||||
/**
|
||||
* @brief 16 字节对齐、静态变量不影响类的大小、vptr指针=8
|
||||
*/
|
||||
cout<<sizeof(A)<<endl;
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user