C++ error: object of abstract class type is not allowed: pure virtual function has no overrider

Your functions should be:-

float getArea() const {return getRadius() * getRadius() * PI;}
float getPerimeter() const {return getRadius() * 2 * PI;}

REASON FOR THIS BEHAVIOR :-

When you re-define a function in derived class with same parameters as in base class then that’s called as overriding. Whereas if you re-define that function with different parameter then it would be an attempt to use overloading from you side. But overloading is possible only in class scope. So, in this case corresponding base class function would be hidden.

For e.g:- Below is futile attempt on overloading.

class Base
{
public:
   virtual void display () const;
};

class Derived 
{
public:
   virtual void display ();
};

int main()
{
    const Derived d;
    d.display();           //Error::no version defined for const....
}

So you are getting error as display in derived would hide display in base.

Similarly your pure virtual function would be hidden i.e compiler treat that case as there is no function defined in derived corresponding to base class pure virtual function.That would make derived also a abstract class.

Hope things are crystal clear…

Leave a Comment