Avoiding abstract

Henning Hasemann hhasemann at web.de
Fri Jun 1 02:49:21 PDT 2007


If I got you right your problem is: You want to use specific methods of
derived objects without having to cast them for easy access.
But you only have a base-class reference available because the method
that returns the "head" (whatever that means in your case) is available
in all classes and declared in your base class.

I would try this:

* Implement head() in your base class, throwing an exception
* Derive head but return exactly the type you want to return

If that doesnt work, because you dont know what head() will return
for each class in advance, let them all return Expr (as you do now)
and implement your rawSymName() etc... methods in the base class
throwing an exception by default.
Now you only need to override them where you actually need them.

Only problem with this is, that the virtual dispatch is done at
runtime, so you can theoretically never be sure if you will get
a runtime error somewhen because of a typo or something.

Henning

-- 
GPG Public Key: http://keyserver.veridis.com:11371/search?q=0x41911851
Fingerprint: 344F 4072 F038 BB9E B35D  E6AB DDD6 D36D 4191 1851


More information about the Digitalmars-d-learn mailing list