The base class here is Rectangle and it is a template class. I have derived a class called ColorRectangle from Rectangle and it is also a template class. But ColorRectangle cannot access the protected data members of Rectangle. How can I solve this?
Rectangle header file
#include<iostream>
using namespace std;
template <class T>
class Rectangle{
protected:
T length;
T breadth;
public:
void setLength(T len){
length = len;
}
void setBreadth(T bre){
breadth = bre;
}
T getLength(){
return length;
}
T getBreadth(){
return breadth;
}
T area(){
return length*breadth;
}
};
ColorRectangle Header file
#include<iostream>
#include"Rectangle.h"
using namespace std;
template <class T>
class ColorRectangle:public Rectangle<T>{
private:
T borderWidth;
string borderColor;
public:
void setBwidth(T bw){
borderWidth = bw;
}
void setColor(string bc){
borderColor = bc;
}
T calcPerimeter(){
return 2 * (length + breadth);
}
};