Re: access subclass functions

2008-11-21 Thread Saaa
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? >

Re: access subclass functions

2008-11-21 Thread Kagamin
Saaa Wrote: > >> this wrong: > >> fruits[BANANA].peel(); > > > > why not using struct? > > How do you mean? > What should be a struct? > typed array.

Re: access subclass functions

2008-11-20 Thread Saaa
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

Re: access subclass functions

2008-11-20 Thread Christopher Wright
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

Re: access subclass functions

2008-11-20 Thread Saaa
> 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:

Re: access subclass functions

2008-11-20 Thread Jarrett Billingsley
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.

Re: access subclass functions

2008-11-20 Thread Christopher Wright
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

Re: access subclass functions

2008-11-20 Thread BCS
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() );

Re: access subclass functions

2008-11-20 Thread Saaa
"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?

Re: access subclass functions

2008-11-20 Thread Saaa
> > > 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. > } > } > >

Re: access subclass functions

2008-11-20 Thread Kagamin
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?

Re: access subclass functions

2008-11-20 Thread Saaa
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

Re: access subclass functions

2008-11-20 Thread Steven Schveighoffer
"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

Re: access subclass functions

2008-11-20 Thread sclytrack
== 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

Re: access subclass functions

2008-11-20 Thread Saaa
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

Re: access subclass functions

2008-11-20 Thread Steven Schveighoffer
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

access subclass functions

2008-11-20 Thread Saaa
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