C++ | Virtual Functions | Question 12

Last Updated :
Discuss
Comments
Predict the output of following C++ program. Assume that there is no alignment and a typical implementation of virtual functions is done by the compiler. C
#include <iostream>
using namespace std;

class A
{
public:
    virtual void fun();
};

class B
{
public:
   void fun();
};

int main()
{
    int a = sizeof(A), b = sizeof(B);
    if (a == b) cout << "a == b";
    else if (a > b) cout << "a > b";
    else cout << "a < b";
    return 0;
}
a > b
a == b
a < b
Compiler Error
Share your thoughts in the comments