c++ - Size of class with virtual keyword and character in it -


this question has answer here:

i ran following code.

#include <iostream> using namespace std;  class base {       char c;      public:          virtual ~base()         {         } };  int main() {      cout << sizeof(base) << endl;   return 0; } 

1) size 4 (for vptr) + 1(for char). result 8. why ?

2) replaced char int variable, still output 8. can explain me has caused issue?

it's down padding. compiler has packed class multiple of 4 bytes.


Comments

Popular posts from this blog

Magento/PHP - Get phones on all members in a customer group -

php - .htaccess mod_rewrite for dynamic url which has domain names -

Website Login Issue developed in magento -