I have a base class
class Shape{
public:
virtual int getArea()=0;
}
I want to change the signature while overriding
like this:
class Rectangle : class Shape{
public:
int getArea(int someParameter = 0){
return 0;
}
}
Is it possible somehow to achieve this, as I am using default value for newly added parameter?
The only solution I can see is that you implement both
int getArea()
andint getArea(int)
, where one function can call the other (for exampleint getArea() { return getArea(0); }
). You can not have the overload taking an argument have a default argument then.