Is it possible to overload a variable in a derived class? Example:
1 2 3 4 5 6 7 8 9 10 11 12 13
struct Circle
{
int radius() const { return r; }
private:
int r;
}
struct Smiley : Circle
{
// inherits the function int radius() const, but doesn't return Smiley::r
private:
int r;
}
It is not an overloading. The derived class has two data members with the same name r one of which is accessible in it and other is not accessible directly. I do not see any sense in such a declaration. It follows that Circle has its own radius and Smiley has its own additional radius. So one figure has two radiuses.
There is no need to assign variable r of class Circle protected access control because class Circle provides public interface to the variable via member function radius. So it would be better to define classes the following way
@benbalach
Everything works! How does the line of code above work exactly? I mean I know what it does, it's just I haven't seen it before. Thanks in advance!
Here the base class constructor with parameter is called explicitly, Otherwise the compiler would try to call the default base class constructor which is absent,
The similar effect could be achived if to use using declaration in the drived class.