class subclass : public superclass{
//code
};
class Shape{
private:
int width;
int height;
public:
Shape(int w,int h):width{w},h{height}{}
};
class Rectangle : public Shape{
public:
int getArea(){return width*height;}
};
#include <iostream>
using namespace std;
int main(){
Rectangle rec{5,6};
cout<<getArea();
}
Since width,length are private in Shape, subclass Rectangle cannot access them. How to solve it?