I have this code:
class A
{
public:
virtual void FA()=0;
};
class B: public A
{
public:
virtual void FB()=0;
};
class Imp_A: public A
{
public:
void FA()
{
// implement FA
}
};
class Imp_B :public Imp_A, public B
{
public:
void FB()
{
// implement FB by calling FA()
FA();
// do some more work here.
}
};
in class Imp_B, I don't want to implement FA as it is already implemented in Imp_A which this class is based.
But when I try to compile my code, I am getting error that Imp_B is virtual and can not be instantiated.
also when I try to call FA inside FB, I am getting error that FA is ambiguous.
How can I solve this problem?
Please note that Imp_A is based on A and implement it, Imp_B is based on Imp_A and B and the idea is that it uses implementation of A from imp_A and only implement B.
Aorimp_A. To get around this you will need to prefix it with the base class you're wanting to implement it from so if you wanted to use class A then you would putA::FA. You cannot instantiate virtual methods but you can ovverride them so you would need to specify that you're overriding the method. I haven't used C# in a while so I can't remember the exact syntax (hence why I'm commenting rather than answering).FA();is ambiguous (cannot decide betweenA::FAthat came viaB, andA::FAthat came viaImp_A). "Imp_B is virtual and can not be instantiated" is a cascade that should be ignored (it happened because the failure ofFA();to compile means thatFB() { .... }did not compile, so the class was not considered to have overriden the pure virtual definition)