access subclass functions
sclytrack
sclytrack at pi.be
Thu Nov 20 05:26:05 PST 2008
== Quote from Saaa (empty at needmail.com)'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();
> Error: no property 'peel' for type 'project.fruitclass.Fruit'
> Error: function expected before (), not 1 of type int
> Error: cannot implicitly convert expression (cast(Banana)1()) of type
> 'project.banana.Banana' to bool
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 = new Banana();
bool f = a.peel(); //visible only when public
All non-static non-private non-template member functions are virtual.
(Rule only valid in D)
If you want to peel your fruit your fruit needs a peel member function,
or else you need to cast it (dynamic_cast). You can make an abstract
virtual function (pure virtual function).
What kind of a programme are you making? Just curious.
More information about the Digitalmars-d-learn
mailing list