| Thread overview | ||||||
|---|---|---|---|---|---|---|
|
March 11, 2015 Bypass the protection level | ||||
|---|---|---|---|---|
| ||||
Let's say we have these files:
----
module Foo.Graphic.Drawable;
interface Drawable {
void draw(bool);
}
----
----
module Foo.Graphic.Sprite;
import Foo.Graphic.Drawable;
class Sprite : Drawable {
protected:
void draw(bool enable) {
import core.stdc.stdio : printf;
if (enable)
printf("draw\n");
else
printf("no drawing...\n");
}
}
----
----
module Foo.Window.Window;
import Foo.Graphic.Drawable;
class Window {
void draw(Drawable d) {
d.draw(true);
}
}
----
I can call draw on Drawable, because it is declared public and I cannot call draw on Sprite because it is declared protected (this is already a bit weird, why can I redeclare the interface method draw as protected?) but I can call the protected draw method from Sprite through Drawable. Is this intended?
| ||||
March 11, 2015 Re: Bypass the protection level | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Namespace | Could it be that this is intentional and has always worked? | |||
March 11, 2015 Re: Bypass the protection level | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Namespace | On 03/11/2015 04:40 AM, Namespace wrote: > I can call draw on Drawable, because it is declared public and I cannot > call draw on Sprite because it is declared protected (this is already a > bit weird, why can I redeclare the interface method draw as protected?) It is the same in C++. > but I can call the protected draw method from Sprite through Drawable. > Is this intended? As far as I know, yes it's intended and again the same in C++. Ali | |||
March 11, 2015 Re: Bypass the protection level | ||||
|---|---|---|---|---|
| ||||
Posted in reply to Ali Çehreli | On Wednesday, 11 March 2015 at 15:22:43 UTC, Ali Çehreli wrote:
> On 03/11/2015 04:40 AM, Namespace wrote:
>
> > I can call draw on Drawable, because it is declared public
> and I cannot
> > call draw on Sprite because it is declared protected (this is
> already a
> > bit weird, why can I redeclare the interface method draw as
> protected?)
>
> It is the same in C++.
>
> > but I can call the protected draw method from Sprite through
> Drawable.
> > Is this intended?
>
> As far as I know, yes it's intended and again the same in C++.
>
> Ali
o.O nice to know. Thank you.
| |||
Copyright © 1999-2021 by the D Language Foundation
Permalink
Reply