C++ Doodling | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

C++ Doodling

You are making a drawing application. The code you are given declares a Shape base class, and you are making separate classes for each shape that your application is going to support. Inherit the Rectangle class from the Shape class and call its draw() method. Inherit using a colon and an access specifier. #include <iostream> using namespace std; class Shape { public: void draw() { cout << "Drawing..."; } }; //inherit from Shape class Rectangle: Shape { private: int width; int height; public: Rectangle(int w, int h): width(w), height(h) { cout <<w<<"x"<<h<<endl; }; }; int main() { int x, y; cin>>x>>y; Rectangle d(x, y); //call the draw() method d.draw(); } Could someone tell me what i'm doing wrong?

20th Oct 2021, 4:17 PM
Alex Ramsey
2 Answers
+ 1
I read something like access specifier in the text above. What is with this: class Rectangle: public Shape
20th Oct 2021, 4:34 PM
Coding Cat
Coding Cat - avatar
+ 1
U missing access specifiers while inheriting class #include <iostream> using namespace std; class Shape { public: void draw() { cout << "Drawing..."; } }; //inherit from Shape class Rectangle: public Shape { private: int width; int height; public: Rectangle(int w, int h): width(w), height(h) { cout <<w<<"x"<<h<<endl; }; }; int main() { int x, y; cin>>x>>y; Rectangle d(x, y); //call the draw() method d.draw(); }
20th Oct 2021, 5:30 PM
A S Raghuvanshi
A S Raghuvanshi - avatar