Quick Q: Accessing protected members in a derived class

Save to:
Instapaper Pocket Readability

Quick A: Only your own type can be accessed.

Recently on SO:

Accessing protected members in a derived class

You can only access protected members in instances of your type (or derived from your type).
You cannot access protected members of an instance of a parent or cousin type.

In your case, the Derived class can only access the b member of a Derived instance, not of a different Base instance.

Changing the constructor to take a Derived instance will also solve the problem.

Add a Comment

Comments are closed.

Comments (0)

There are currently no comments on this entry.