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



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

having problem inheritance. have no thought i'm doing wrong.

figuregeometry.h

#ifndef figuregeometry #define figuregeometry static const float pi = 3.14159f; class figuregeometry { public: virtual float getarea() const = 0; virtual float getperimeter() const = 0; }; #endif

circle.h

#ifndef circle #define circle #include "figuregeometry.h" class circle:public figuregeometry { float radius; public: circle(float theradius) { radius = theradius; } float getradius() {return radius;} float getarea() {return getradius() * getradius() * pi;} float getperimeter() {return getradius() * 2 * pi;} }; #endif

and in main.cpp, on line containing "circle c1(5);" error:

21 intellisense: object of abstract class type "circle" not allowed: pure virtual function "figuregeometry::getarea" has no overrider pure virtual function "figuregeometry::getperimeter" has no overrider c:\users\moog\documents\visual studio 2012\projects\data structures 3\data structures 3\main.cpp 9 9 info structures 3

your functions should be:-

float getarea() const {return getradius() * getradius() * pi;} float getperimeter() const {return getradius() * 2 * pi;}

reason behavior :-

when re-define function in derived class same parameters in base of operations class that's called overriding. whereas if re-define function different parameter effort utilize overloading side. overloading possible in class scope. so, in case corresponding base of operations class function hidden.

for e.g:- below futile effort on overloading.

class base of operations { public: virtual void display () const; }; class derived { public: virtual void display (); }; int main() { const derived d; d.display(); //error::no version defined const.... }

so getting error display in derived hide display in base.

similarly pure virtual function hidden i.e compiler treat case there no function defined in derived corresponding base of operations class pure virtual function.that create derived abstract class.

hope things crystal clear...

c++

Comments

Popular posts from this blog

assembly - What is the addressing mode for ld, add, and rjmp instructions? -

vowpalwabbit - Interpreting Vowpal Wabbit results: Why are some lines appended by "h"? -

Is there a way to convert an HTML page styled with Bootstrap CSS into email-compatible html? -