I thought pure virtual functions have complete access to the private members of the base class, since the prototype of the function is declared in the base class but then later defined in a derived class.
Please look at the example below to see what I mean.
class Circle : public BasicShape
{
longint centerX;
longint centerY;
double radius;
public:
Circle (longint x, longint y, double r)
{
centerX = x;
centerY = y;
radius = r;
calcArea ();
}
longint getCenterX ()
{
return centerX;
}
longint getCenterY ()
{
return centerY;
}
virtualvoid calcArea ()
{
area = (3.14159 * radius * radius); //shouldn't this function have access to the private member area?
}
};
p.s I know i can simply just declare the member area a protected member to make this work, but I want to find out whether or not a pure virtual function will have access to a private member.
[quote]//shouldn't this function have access to the private member area?[/quote
NO.
Its is not a member of the base class nor a friend of it. Its a function of the derived class that overrides that of the base class.
Having a pure virtual method just means that the derived class MUST provide a definition for that function, but the inheritance still works like it would otherwise.