How to solve the Diamond Problem without using virtual function

Viewed 112
#include<iostream>
using namespace std;
class student{
    public:
        int a;
        get_a(){
            cout<<"Give value of a"; cin>>a;
        }
};
class student1: public student{
    public:
        int b;
        get_b(){
            cout<<"Give value of b"; cin>>b;
        }
};
class student2:public student{
    public:
        int c;
        get_c(){
            cout<<"Give value of c"; cin>>c;
        }
};
class student3: public student1,public student2{
    public:
        int d;
        get_d(){
            cout<<"Give value of d"; cin>>d;
        }
};
main(){
    student3 x;
    x.get_a;
    x.get_b;
    x.get_c;
    x.get_d;
    cout<<"a= "<<a;
    cout<<"b= "<<b;
    cout<<"c= "<<c;
    cout<<"d= "<<d;
}

i have this code as an example and we were given an openbook task to search for an answer on how to solve this code without using virtual keyword. i tired searching on google and tried myself but couldnt do it. so can anyone help?

0 Answers
Related