Wballer3
Wballer3

Reputation: 151

Abstract class inheriting another abstract class in C++

I have a class which has a pure virtual function declared, like this:

class A : public virtual B
{
public:

   virtual void setOn() = 0;

   virtual void setOff() = 0;
};

Now, class B is also abstract:

class B
{
public:

   virtual const ElementId& getElementId() const = 0;

   virtual const std::string& getName() const = 0;

   virtual ~B();

};

My question is how class A can be valid, since it does not provide the implementation of the pure virtual methods in class B?

Upvotes: 3

Views: 3847

Answers (1)

Hatted Rooster
Hatted Rooster

Reputation: 36463

A class that inherits from an abstract class does not have to implement the pure virtual methods. Not doing so it becomes an abstract class itself which means in this case that A is also an abstract class regardless of other pure virtual methods declared in A.

Upvotes: 14

Related Questions