In implementations of pure virtual classe (B_Impl below) do we need to define all methods corresponding to all derived pure virtual classes (A and B) even if we are also deriving from implementation classes (A_Impl). I have following pure virtual classes:
class A
{
public:
virtual bool M1() = 0;
virtual ~A() = default;
};
class A_Impl: public virtual A
{
public:
bool M1() override { return true;}
virtual ~A_Impl() = default;
};
class B : public virtual A
{
public:
virtual ~B()=default;
virtual bool M2() = 0;
};
class B_Impl : public B, public A_Impl
{
public:
virtual ~B_Impl() = default;
bool M2() override { return true; }
};
int main()
{
B_Impl bimpl();
return 0;
}
On compiling this I am getting following error:
1.cpp: In function ‘int main()’: 1.cpp:31:5: error: invalid abstract return type ‘B_Impl’ B_Impl bimpl(); ^~~~~~ 1.cpp:22:7: note: because the following virtual functions are pure within ‘B_Impl’: class B_Impl : public B, public A_Impl ^~~~~~ 1.cpp:4:14: note: virtual bool A::M1() virtual bool M1() = 0;
I dont want to define all methods of A in B_Impl as well when I am deriving from A_Impl also.