You mean something like this ?
struct fruits
{
Banana banana();
Apple apple();
}
I now use foreach(int i, Fruit fruit; fruits) a lot.
How do I iterate over all elements when I use the above?
> Saaa Wrote:
>
>> >> this wrong:
>> >> fruits[BANANA].peel();
>> >
>> > why not using struct?
>
Saaa Wrote:
> >> this wrong:
> >> fruits[BANANA].peel();
> >
> > why not using struct?
>
> How do you mean?
> What should be a struct?
>
typed array.
Thanks !!
I miss university :'(
>>> Informally, "virtual" means "can be overridden". It only applies to
>>> methods on classes. This definition is informal and ambiguous.
>> virtual functions are slowers because you have the extra step of
>> vtable, right?
>> How much of a difference can I expect
Saaa wrote:
Informally, "virtual" means "can be overridden". It only applies to
methods on classes. This definition is informal and ambiguous.
virtual functions are slowers because you have the extra step of
vtable, right?
How much of a difference can I expect?
Because it doesn't look like a lot
> Informally, "virtual" means "can be overridden". It only applies to
> methods on classes. This definition is informal and ambiguous.
virtual functions are slowers because you have the extra step of
vtable, right?
How much of a difference can I expect?
Because it doesn't look like a lot of work:
On Thu, Nov 20, 2008 at 7:35 PM, Christopher Wright <[EMAIL PROTECTED]> wrote:
> [1] It's a bit of a stretch to grant them this name, but if life gives you
> lemmas, make lemma-ade.
>
OhhhHH
I think my head just exploded.
Saaa wrote:
from the list (private, protected, public) pick public.
Note the difference between peel and peal.
:)
public YellowBanana: Banana
{
void doStuff()
{
bool e = peel(); //visible from derived
//class when defined protected or public.
}
}
Banana a = ne
Reply to Saaa,
b=cast(Banana)fruits[1].peel();
I'm not shure that will work. IIRC DMD reads that as
b=cast(Banana)( fruits[1].peel() );
"Kagamin" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> Saaa Wrote:
>
>> In stead of numbers I use an enum, which makes it really difficult to get
>> this wrong:
>> fruits[BANANA].peel();
>
> why not using struct?
How do you mean?
What should be a struct?
>
>
> from the list (private, protected, public) pick public.
> Note the difference between peel and peal.
:)
>
>
> public YellowBanana: Banana
> {
> void doStuff()
> {
> bool e = peel(); //visible from derived
>//class when defined protected or public.
> }
> }
>
>
Saaa Wrote:
> In stead of numbers I use an enum, which makes it really difficult to get
> this wrong:
> fruits[BANANA].peel();
why not using struct?
My bad, I meant:
b=cast(Banana)fruits[1].peel();
"Steven Schveighoffer" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> "Saaa" wrote
>>> (and your example doesn't reflect the error messages),
>> How do you mean? Like not at all?
>> As you noticed it isn't the actual code, but I th
"Saaa" wrote
>> (and your example doesn't reflect the error messages),
> How do you mean? Like not at all?
> As you noticed it isn't the actual code, but I thought it would reflect it
> though.
I mean, you have some cast error, but there is no casting in your code
sample.
-Steve
== Quote from Saaa ([EMAIL PROTECTED])'s article
> Is this not possible, or am I doing anything wrong?
> Fruit[2] fruits; // Fruit has no peel function
> fruit[0]= new Apple();
> fruit[1]= new Banana(); //Banana has a protected peel() function returning a
> bool
> bool b;
> b=fruit[1].peal();
> Err
rongly typed language, you cannot access subclass functions that
> aren't defined in the base class unless you are sure the instance is of
> the subclass type.
>
> to fix, you should do this:
>
> if(auto ban = cast(Banana)fruit[1])
> ban.peel();
>
> the if(auto ban
ve a typo in your example (and your example doesn't reflect
the error messages), but that isn't the problem.
In a strongly typed language, you cannot access subclass functions that
aren't defined in the base class unless you are sure the instance is of the
subclass type.
to fix, yo
Is this not possible, or am I doing anything wrong?
Fruit[2] fruits; // Fruit has no peel function
fruit[0]= new Apple();
fruit[1]= new Banana(); //Banana has a protected peel() function returning a
bool
bool b;
b=fruit[1].peal();
Error: no property 'peel' for type 'project.fruitclass.Fruit'
E
17 matches
Mail list logo