jeudi 4 juin 2015

Size of class with virtual keyword and character in it

I ran the following code.

#include <iostream>
using namespace std;

class Base
{  
    char c;

    public:

        virtual ~Base()
        {
        }
};

int main()
{   
  cout << sizeof(Base) << endl;
  return 0;
}

1) The size is 4 (for vptr) + 1(for char). But the result is 8. Why is it so ?

2) I replaced char with a int variable, still the output is 8. Can someone explain me what has caused this issue?

Aucun commentaire:

Enregistrer un commentaire