0
#include<iostream>
using namespace std;
class base
{
 virtual int fun(int i){int j;}
};
int main()
{   base b;
    cout<<sizeof(b);
    return 0;
}

Output: 4

now :

#include<iostream>
using namespace std;
class base
{
 int fun(int i){int j;}     //removed virtual
};
int main()
{   base b;
    cout<<sizeof(b);
    return 0;
}

Output :1

Why is there difference in both outputs??

anatolyg
  • 26,506
  • 9
  • 60
  • 134
Sumant Kumar Mehta
  • 115
  • 1
  • 3
  • 5

0 Answers0