c++ - Object of abstract class type "Rectangle" is not allowed -


//quizshape.h #ifndef quizshape_h #define quizhape_h #include <iostream> #include <iomanip> #include <string>  using namespace std;  class quizshape { protected:     //outer , inner symbols, , label     char border, inner;     string quizlabel; public:     //base class constructor defaults     quizshape(char out = '*', char in = '+', string name = "3x3 square")     {         border = out;         inner = in;         quizlabel = name;         cout << "base class constructor, values set" << endl << endl;     };      //getters     char getborder() const     { return border; }     char getinner() const     { return inner; }     string getquizlabel() const     { return quizlabel; }      //virtual functions defined later     virtual void draw( ) = 0;     virtual int getarea( ) = 0;     virtual int getperimeter( ) = 0;  };   class rectangle : public quizshape { protected:     //height , of rectangle drawn     int height, width; public:     //derived class constructor     rectangle(char out, char in, string name,                 int h = 3, int w = 3):quizshape(out, in, name)     {         height = h;         width = w;         cout << "derived class constructor, values set" << endl << endl;     }      //getters     int getheight() const     { return height; }     int getwidth() const     { return width; }      //*********************************************     virtual void draw(const rectangle &rect1)     {         cout << "draw func" << endl;         cout << rect1.height << endl;         cout << rect1.getwidth() << endl;         cout << rect1.getquizlabel() << endl;     }      virtual int getarea(const rectangle &rect2)     {         cout << "area func" << endl;         cout << rect2.getinner() << endl;         cout << rect2.getborder() << endl;     }      virtual int getperimeter(const rectangle &rect3)     {         cout << "perim func" << endl;         cout << rect3.height << endl;         cout << rect3.getwidth() << endl;         cout << rect3.getquizlabel() << endl;        }     //************************************************ };    #endif 

these class types far.

//quizshape.cpp #include "quizshape.h" 

this nothing bridge files.

//pass7.cpp #include "quizshape.cpp"  int main() {     rectangle r1('+', '-', "lol", 4, 5);      cout << r1.getheight() << endl;     cout << r1.getwidth() << endl;     cout << r1.getinner() << endl;     cout << r1.getborder() << endl;     cout << r1.getquizlabel() << endl;      system("pause");     return 0; } 

the code not compile due fact rectangle supposedly abstract class, , when hovering on declaration of r1 in main, receive error

"object of abstract class type "rectangle" not allowed".

i have checked other answers on site , others , have not come across solves problem.

note: understand statements virtual functions ending in =0; cause class become abstract one. quizshape should abstract. have defined virtual functions in rectangle , yet remains abstract class.

how can modify virtual functions rectangle class rectangle no longer abstract?

your methods int abstract class quizshape are:

virtual void draw( ) = 0; virtual int getarea( ) = 0; virtual int getperimeter( ) = 0; 

but in rectangle take const rectangle &rect1 parameter shadowing methods , not overriding abstract 1 @ all. need have methods in rectangle same signature ones in abstract base class.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -