mirror of
https://github.com/Light-City/CPlusPlusThings.git
synced 2026-02-11 14:35:01 +08:00
support bazel complie this project and format code.
This commit is contained in:
@@ -8,15 +8,14 @@
|
||||
* @date 2019-07-21
|
||||
*/
|
||||
|
||||
#include<iostream>
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
|
||||
class A
|
||||
{
|
||||
public:
|
||||
char a;
|
||||
int b;
|
||||
class A {
|
||||
public:
|
||||
char a;
|
||||
int b;
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -34,39 +33,32 @@ class A
|
||||
* long b
|
||||
* 根据字节对齐2+2+4+8=16
|
||||
*/
|
||||
class B:A
|
||||
{
|
||||
public:
|
||||
short a;
|
||||
long b;
|
||||
class B : A {
|
||||
public:
|
||||
short a;
|
||||
long b;
|
||||
};
|
||||
/**
|
||||
* 把A的成员拆开看,char为1,int为4,所以是1+(3)+4+1+(3)=12,()为字节补齐
|
||||
*/
|
||||
class C
|
||||
{
|
||||
A a;
|
||||
char c;
|
||||
* 把A的成员拆开看,char为1,int为4,所以是1+(3)+4+1+(3)=12,()为字节补齐
|
||||
*/
|
||||
class C {
|
||||
A a;
|
||||
char c;
|
||||
};
|
||||
|
||||
class A1
|
||||
{
|
||||
virtual void fun(){}
|
||||
};
|
||||
class C1:public A
|
||||
{
|
||||
class A1 {
|
||||
virtual void fun() {}
|
||||
};
|
||||
class C1 : public A {};
|
||||
|
||||
int main() {
|
||||
cout << sizeof(A) << endl; // 8
|
||||
cout << sizeof(B) << endl; // 16
|
||||
cout << sizeof(C) << endl; // 12
|
||||
|
||||
int main()
|
||||
{
|
||||
cout<<sizeof(A)<<endl; // 8
|
||||
cout<<sizeof(B)<<endl; // 16
|
||||
cout<<sizeof(C)<<endl; // 12
|
||||
|
||||
/**
|
||||
* @brief 对于虚单函数继承,派生类也继承了基类的vptr,所以是8字节
|
||||
*/
|
||||
cout<<sizeof(C1)<<endl; // 8
|
||||
return 0;
|
||||
/**
|
||||
* @brief 对于虚单函数继承,派生类也继承了基类的vptr,所以是8字节
|
||||
*/
|
||||
cout << sizeof(C1) << endl; // 8
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user