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
  • 24,991
  • 8
  • 55
  • 121
Sumant Kumar Mehta
  • 125
  • 1
  • 3
  • 5

0 Answers0