0

I was learning about virtual function that whenever a class has virtual function as member function in it then compiler creates a *_vptr pointer in that class.

#include<bits/stdc++.h>
using namespace std;
class A
{
    int a;
    int b;
    int c;
    public:
        A()
        {
            
        }
        virtual void f1()
        {
        }
        virtual void f2()
        {
        }
};
int main()
{
    A obj;
    cout<<sizeof(obj);
    return 0;
}  

So according to this concept size of my class A should be 20 bytes. Assuming size of int as 4 bytes and size of pointer as 8 bytes. But in compiler it is showing 24 bytes? Why this is happening?

  • See [Why should I not #include ?](https://stackoverflow.com/q/31816095) and [Why using namespace std is bad practice](https://stackoverflow.com/questions/1452721). – prapin Aug 15 '21 at 15:32

0 Answers0