|
|
I have a question about access control in C++:
// base.h
class base
{
protected:
virtual int f() { return -1; }
};
--------------------------------------------------------------------
// derived.h
class derived : public base
{
private:
base* b;
protected:
virtual int f() {
b = new base();
return b->f();
}
};
--------------------------------------------------------------------
This doesn't compile. Why not? How can I call b's version of f()?
Thanks!
|
|
|
|
|
A member (either data member or member function) declared in a protected section of a class can only be accessed by member functions and friends of that class, and by member functions and friends of derived classes
|
|
|
|
|
|
|
|
|
|