protected behaviour on base class member access from another module
Boris-Barboris via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sun Apr 30 10:09:54 PDT 2017
Hi!
I have a base class in module A:
module A;
...
class GuiElement: GuiComponent
{
protected
{
GuiElement _parent;
...
}
template isGuiElement(T)
{
enum isGuiElement = is(T: GuiElement);
}
...
and derived class in module B:
module B;
...
class Div(uint dim, uint odim): GuiElement
{
protected GuiElement[] children;
this(Children...)(GuiManager manager, Children kids)
if (allSatisfy!(isGuiElement, Children))
{
super(manager);
children = [kids];
this._parent = null; <- This works
foreach (kid; children)
kid._parent = this; <- Error: class A.GuiElement
member _parent is not accessible
A couple of questions:
1). Is this intended?
2). If yes, why? What is the reasoning behind such restriction?
Quoting the docs: "...a symbol can only be seen by members of the
same module, or by a derived class...".
3). What does the cryptic "If accessing a protected instance
member through a derived class member function, that member can
only be accessed for the object instance which can be implicitly
cast to the same type as ‘this’" mean?
Let's say B derives from A, and B instance has a method that
accesses A.protected_member inside of it. What does member access
have to do with it? Why does this sentence jump from member to
method, back to member, and then to some object that was never
mentioned before? Objects don't request access, statements do.
`this` of who?
More information about the Digitalmars-d-learn
mailing list