C ++ on the type and size of the empty size of the virtual function is present

BS, directly on the code

#include<iostream>
using namespace std;

class A{
};

class B{
        B(){}
        ~B(){}
};

class C{
        C(){}
        virtual ~C(){}
};

int main(){
        cout<<"A的大小:"<<sizeof(A)<<endl;
        cout<<"B的大小:"<<sizeof(B)<<endl;
        cout<<"C的大小:"<<sizeof(C)<<endl;
}

what's the result?

The following is to prove safety of the explanation OFFER:

Explain in great detail.

My machine is 64, so the result is:

 

expand:

If a class has both a virtual function?

class D{
        D(){}
        virtual ~D(){}
        virtual void func(){}
};

And as a result a virtual function, or 64.

Because sizeof size class with a virtual function, and the number of virtual functions in fact not relevant, is associated virtual function pointers.

Published 20 original articles · won praise 3 · Views 465

Guess you like

Origin blog.csdn.net/qq_41655075/article/details/104007352