Read in your tongue here..

Sunday, December 8, 2013

Ambiguity in Multiple Inheritance

#include<iostream.h>
#include<conio.h>
class first{
    protected:
        int num;    //same data member name
    public:
        void func(int x)    //same member function name
        {
            num=x;
            cout<<"\nFirst Num= "<<num;
        }
};
class second{
    protected:
        int num;    //same data member name
    public:
        void func(int y)    //same member function name
        {
            num=y;
            cout<<"\nSecond Num= "<<num;
        }
};
class third: public first, public second{
    int num;    //same data member name
    public:
    void func(void)        //same member function name
    {

        num=first::num+second::num;
        cout<<"\nSum of both Num= "<<num;
    }
};
void main()
{
    third ob;        //creating object for class third
    ob.first::func(3);    //calling func of class first for ob
    ob.second::func(45);    //calling func of class second for ob
    ob.func();        //calling func of class third for ob
    getch();
    clrscr();
}

No comments:

Post a Comment