Multiple Inheritance problem
-
Hi all, I have one problem in using Multiple Inheritance, please go through below Code
class Base1
{
public:
void Show()
{
cout<<"Base1";
}};
class Base2
{
public:
void Show()
{
cout<<"Base2";
}
};
class Derived: public Base1,public Base2
{
}
main()
{
Derived d;
d.Show();
}Error: error C2385: ambiguous access of 'show' Please provide some solution for the above code. Can virtual Base class concept work in this,if yes then how?
-
Hi all, I have one problem in using Multiple Inheritance, please go through below Code
class Base1
{
public:
void Show()
{
cout<<"Base1";
}};
class Base2
{
public:
void Show()
{
cout<<"Base2";
}
};
class Derived: public Base1,public Base2
{
}
main()
{
Derived d;
d.Show();
}Error: error C2385: ambiguous access of 'show' Please provide some solution for the above code. Can virtual Base class concept work in this,if yes then how?
-
Symfund wrote:
What's the difference between upcasting and downcasting?
I am sorry but,I didn't get how this question answers my question?
-
Hi all, I have one problem in using Multiple Inheritance, please go through below Code
class Base1
{
public:
void Show()
{
cout<<"Base1";
}};
class Base2
{
public:
void Show()
{
cout<<"Base2";
}
};
class Derived: public Base1,public Base2
{
}
main()
{
Derived d;
d.Show();
}Error: error C2385: ambiguous access of 'show' Please provide some solution for the above code. Can virtual Base class concept work in this,if yes then how?
Rahul Vaishnav wrote:
d.Show();
The error is because the compiler do not know which Show() function it should call. Show() of Base1 or Base2. Actually which one do you want to call? You have to tell the compiler which one excatly. like
d.Base1::Show();
ord.Base2::Show();
nave [My Articles] [My Blog]
-
Hi all, I have one problem in using Multiple Inheritance, please go through below Code
class Base1
{
public:
void Show()
{
cout<<"Base1";
}};
class Base2
{
public:
void Show()
{
cout<<"Base2";
}
};
class Derived: public Base1,public Base2
{
}
main()
{
Derived d;
d.Show();
}Error: error C2385: ambiguous access of 'show' Please provide some solution for the above code. Can virtual Base class concept work in this,if yes then how?
Why do you need such multiple inheritance? :)
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
And what are the differences between Bose-Einstein and Dirac-Fermi statistics? :-D
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles] -
Rahul Vaishnav wrote:
d.Show();
The error is because the compiler do not know which Show() function it should call. Show() of Base1 or Base2. Actually which one do you want to call? You have to tell the compiler which one excatly. like
d.Base1::Show();
ord.Base2::Show();
nave [My Articles] [My Blog]
Thank you...
-
And what are the differences between Bose-Einstein and Dirac-Fermi statistics? :-D
If the Lord God Almighty had consulted me before embarking upon the Creation, I would have recommended something simpler. -- Alfonso the Wise, 13th Century King of Castile.
This is going on my arrogant assumptions. You may have a superb reason why I'm completely wrong. -- Iain Clarke
[My articles]